Project

General

Profile

Bug #15027 » struct_enumerable_fix2.patch

Updated patch - bruno (Bruno Sutic), 09/01/2018 04:04 PM

View differences:

struct.c
static VALUE
rb_struct_to_a(VALUE s)
{
if (!rb_method_basic_definition_p(CLASS_OF(s), idEach)) {
return rb_call_super(0, 0);
}
return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_CONST_PTR(s));
}
......
rb_check_arity(argc, 0, 0);
RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
if (!rb_method_basic_definition_p(CLASS_OF(s), idEach)) {
return rb_call_super(argc, argv);
}
result = rb_ary_new();
for (i = 0; i < RSTRUCT_LEN(s); i++) {
if (RTEST(rb_yield(RSTRUCT_GET(s, i)))) {
test/ruby/test_struct.rb
}
end
def test_enumerable_methods
klass = @Struct.new(:a)
x = klass.new("test")
assert_equal(["test"], x.to_a)
assert_equal(["test"], x.select { |member| member })
end
def test_enumerable_methods_with_overridden_each
klass = @Struct.new(:a) do
def each(&block)
a.each_char(&block)
end
end
x = klass.new("test")
assert_equal(["t", "e", "s", "t",], x.to_a)
assert_equal(["t", "e", "s", "t",], x.select { |member| member })
end
class TopStruct < Test::Unit::TestCase
include TestStruct
(2-2/2)