How to remove a key from Hash and get the remaining hash in Ruby/Rails?
问题 To add a new pair to Hash I do: {:a => 1, :b => 2}.merge!({:c => 3}) #=> {:a => 1, :b => 2, :c => 3} Is there a similar way to delete a key from Hash ? This works: {:a => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2} but I would expect to have something like: {:a => 1, :b => 2}.delete!(:a) #=> {:b => 2} It is important that the returning value will be the remaining hash, so I could do things like: foo(my_hash.reject! { |k| k == my_key }) in one line. 回答1: Rails has an except/except!