ruby 2.0 named parameters from a hash
ruby, ruby-2.0
Solution
Seems to work just fine for me.
2.0.0p0 :007 > def smoosh(first: nil, second: nil)
2.0.0p0 :008?> first + second
2.0.0p0 :009?> end
=> nil
2.0.0p0 :010 > params = { first: 'peanut', second: 'butter' }
=> {:first=>"peanut", :second=>"butter"}
2.0.0p0 :012 > smoosh(params)
=> "peanutbutter"
Problem
If I have a method in ruby that takes named arguments... ``` def smoosh(first: nil, second: nil) first + second end ``` Whats the easiest way to pass a hash to that method if the keys match: ``` params = { first: 'peanut', second: 'butter' } smoosh(params) ``` The above produces an argument error. Update: It seems like this might be an issue with how Sinatra parameters work. When I do: ``` get 'a_sinatra_route' do hash = params.clone hash.symbolize_keys! smoosh(hash) end ``` It works fine. It does not work when just passing the params in by themselves. (even though you can access the individual params with the symbol key `params[:attr]`)