ruby-changes:64332
From: Marc-Andre <ko1@a...>
Date: Sat, 19 Dec 2020 18:00:11 +0900 (JST)
Subject: [ruby-changes:64332] 0d3dc2ec80 (master): Make `Hash#except` always return a Hash
https://git.ruby-lang.org/ruby.git/commit/?id=0d3dc2ec80 From 0d3dc2ec807c313d0952d15ac4f30bc8586bba2f Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune <github@m...> Date: Thu, 17 Dec 2020 14:43:11 -0500 Subject: Make `Hash#except` always return a Hash [Feature #15822] diff --git a/hash.c b/hash.c index 2f53c24..9b4c315 100644 --- a/hash.c +++ b/hash.c @@ -2643,7 +2643,8 @@ rb_hash_except(int argc, VALUE *argv, VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L2643 int i; VALUE key, result; - result = rb_obj_dup(hash); + result = hash_alloc(rb_cHash); + hash_copy(result, hash); for (i = 0; i < argc; i++) { key = argv[i]; diff --git a/spec/ruby/core/hash/except_spec.rb b/spec/ruby/core/hash/except_spec.rb index cef99b6..82cfced 100644 --- a/spec/ruby/core/hash/except_spec.rb +++ b/spec/ruby/core/hash/except_spec.rb @@ -20,14 +20,15 @@ ruby_version_is "3.0" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/except_spec.rb#L20 @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } end - it "returns an instance of a subclass" do + it "always returns a Hash without a default" do klass = Class.new(Hash) - h = klass.new + h = klass.new(:default) h[:bar] = 12 h[:foo] = 42 r = h.except(:foo) r.should == {bar: 12} - r.class.should == klass + r.class.should == Hash + r.default.should == nil end end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/