summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-15 14:03:28 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-02 13:42:31 -0700
commit1994adf938afcdc562f87497156e6d4900f3f06b (patch)
tree12cb5d84f7b2f6779703bc55150357e50bd41bbb /array.c
parenta848b62819c78e12c420b1ed29605242e292358b (diff)
downloadruby-1994adf938afcdc562f87497156e6d4900f3f06b.tar.gz
Make Array#uniq return subclass instance if called on subclass instance
Previously, Array#uniq would return subclass instance if the length of the array were 2 or greater, and would return Array instance if the length of the array were 0 or 1. Fixes [Bug #7768]
Diffstat (limited to 'array.c')
-rw-r--r--array.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/array.c b/array.c
index bc5c719267..3717c3ff34 100644
--- a/array.c
+++ b/array.c
@@ -4991,9 +4991,11 @@ rb_ary_uniq(VALUE ary)
{
VALUE hash, uniq;
- if (RARRAY_LEN(ary) <= 1)
- return rb_ary_dup(ary);
- if (rb_block_given_p()) {
+ if (RARRAY_LEN(ary) <= 1) {
+ hash = 0;
+ uniq = rb_ary_dup(ary);
+ }
+ else if (rb_block_given_p()) {
hash = ary_make_hash_by(ary);
uniq = rb_hash_values(hash);
}
@@ -5002,7 +5004,9 @@ rb_ary_uniq(VALUE ary)
uniq = rb_hash_values(hash);
}
RBASIC_SET_CLASS(uniq, rb_obj_class(ary));
- ary_recycle_hash(hash);
+ if (hash) {
+ ary_recycle_hash(hash);
+ }
return uniq;
}