Set proper class to subclass of Array
More compatibility to CRuby.
MODIFY
src/array.c
src/array.c
@@ -242,14 +242,19 @@ mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len)
}
static mrb_value
-mrb_ary_s_create(mrb_state *mrb, mrb_value self)
+mrb_ary_s_create(mrb_state *mrb, mrb_value klass)
{
+ mrb_value ary;
mrb_value *vals;
mrb_int len;
+ struct RArray *a;
mrb_get_args(mrb, "*", &vals, &len);
+ ary = mrb_ary_new_from_values(mrb, len, vals);
+ a = mrb_ary_ptr(ary);
+ a->c = mrb_class_ptr(klass);
- return mrb_ary_new_from_values(mrb, len, vals);
+ return ary;
}
static void

MODIFY
test/t/array.rb
test/t/array.rb
@@ -13,6 +13,14 @@ assert('Array.[]', '15.2.12.4.1') do
assert_equal([1, 2, 3], Array.[](1,2,3))
end
+class SubArray < Array
+end
+
+assert('SubArray.[]') do
+ a = SubArray[1, 2, 3]
+ assert_equal(SubArray, a.class)
+end
+
assert('Array#+', '15.2.12.5.1') do
assert_equal([1, 1], [1].+([1]))
end

Set proper class to subclass of Array

More compatibility to CRuby.