aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-01 14:05:49 +0000
committercharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-01 14:05:49 +0000
commit86aa98fed4de1be2e868877fd786d3616d6c6ad5 (patch)
tree9d95c060798cd5aabf20a79f312533eac56304ad
parent3fe939564fc5f4dde52a6b9bc385e558e3423256 (diff)
downloadruby-86aa98fed4de1be2e868877fd786d3616d6c6ad5.tar.gz
* array.c (rb_ary_dup): make returned array the same class as the original
array [Bug #7768] [ruby-core:51792] * test/ruby/test_array.rb (class TestArray): add test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--array.c3
-rw-r--r--test/ruby/test_array.rb7
3 files changed, 15 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1bb0e209f5..5d65c8de13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Feb 1 23:04:00 2013 Charlie Somerville <charlie@charliesomerville.com>
+
+ * array.c (rb_ary_dup): make returned array the same class as the original
+ array [Bug #7768] [ruby-core:51792]
+ * test/ruby/test_array.rb (class TestArray): add test
+
Fri Feb 1 16:35:34 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (r_object0): prohibit setting instance variables of
diff --git a/array.c b/array.c
index a7c74a2aa4..b4216ac1d0 100644
--- a/array.c
+++ b/array.c
@@ -1778,7 +1778,8 @@ rb_ary_empty_p(VALUE ary)
VALUE
rb_ary_dup(VALUE ary)
{
- VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
+ VALUE ary_class = rb_obj_class(ary);
+ VALUE dup = ary_new(ary_class ? ary_class : rb_cArray, RARRAY_LEN(ary));
MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
ARY_SET_LEN(dup, RARRAY_LEN(ary));
return dup;
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 3ab0895f8c..c231ecccd1 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2283,4 +2283,11 @@ class TestArray < Test::Unit::TestCase
assert_include([4, 7], a.bsearch {|x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
+
+ def test_array_uniq_returns_same_class # [ruby-core:51792]
+ klass = Class.new(Array)
+ assert_equal klass, klass.new(2).uniq.class
+ assert_equal klass, klass.new(1).uniq.class
+ assert_equal klass, klass.new(0).uniq.class
+ end
end