Get a Ruby hash with one element removed (non-destructive) -
i need new ruby hash based on existing hash 1 element removed , without affecting original hash. i'm sure it's simple, , i'm of ruby newbie spot it.
for example, if have plugh={:bar=>"bar", :baz=>"baz"}
want able xyzzy=plugh.some_magic_goes_here(:baz)
, xyzzy
set {:bar=>"bar"}
without affecting plugh
in way. how do it?
if are not using active support, can following:
xyzzy = plugh.reject { |k, _| k == :baz }
Comments
Post a Comment