fastruby / fast-ruby

:dash: Writing Fast Ruby :heart_eyes: -- Collect Common Ruby idioms.
https://github.com/fastruby/fast-ruby
5.67k stars 376 forks source link

little fix for the hash merge comparison #106

Closed lvl0nax closed 8 years ago

lvl0nax commented 8 years ago

'fast' method has different result from other methods. Because:

ORIGINAL_HASH = { foo: "foo" }
#fast
{ foo: 'bar' }.merge!(ORIGINAL_HASH)
#=> {:foo=>"foo"}

#slow
ORIGINAL_HASH.merge(foo: 'bar')
#=> {:foo=>"bar"}

#slow_dup
ORIGINAL_HASH.dup.merge!(foo: 'bar')
#=> {:foo=>"bar"}

#new fast
{ foo: 'bar' }.merge!(ORIGINAL_HASH){ |_key, left, _right| left }
#=> {:foo=>"bar"}
Arcovion commented 8 years ago

Thanks!