我经常发现自己在写这个:
params.delete(:controller)
params.delete(:action)
params.delete(:other_key)
redirect_to my_path(params)
Run Code Online (Sandbox Code Playgroud)
删除的痕迹感觉不对,也没有:
[:controller, :action, :other_key].each do |k|
params.delete(k)
end
Run Code Online (Sandbox Code Playgroud)
有什么更简单,更清洁的吗?
I'm wondering if it's possible to collet many attributes from a hash.
Currently using ruby 2.6.3
Something like that
hash = { name: "Foo", email: "Bar", useless: nil }
other_hash = hash[:name, :email]
Run Code Online (Sandbox Code Playgroud)
The output should be another hash but without the useless key/value