Alex Rivera | Logout

Delete multiple hash keys

Asked 2009-10-13T14:25:03.607
162

I often find myself writing this:

params.delete(:controller)  
params.delete(:action)  
params.delete(:other_key)  
redirect_to my_path(params)  

The trail of deletes doesn't feel right and neither does:

[:controller, :action, :other_key].each do |k|
  params.delete(k)
end

Is there anything simpler and cleaner?

Edit
Report

1 Answer

28

I'd be completely happy with the code you originally posted in your question.

[:controller, :action, :other_key].each { |k| params.delete(k) }
answered 2009-10-13T15:32:28.713

Your Answer