Skip to content
Permalink
Browse files
Set proper class to subclass of Array
More compatibility to CRuby.
  • Loading branch information
okkez committed Mar 28, 2017
1 parent 5ec051f commit 6dbe2272cf4e1d8262894e03018f3e1b7b763dc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
@@ -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
@@ -13,6 +13,14 @@
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

0 comments on commit 6dbe227

Please sign in to comment.