Ruby – Create a ruby method that accepts a hash of parameters

ruby

I know this may be a stupid question, but I don't know how to create a ruby method that accepts a hash of parameters. I mean, in Rails I'd like to use a method like this:

login_success :msg => "Success!", :gotourl => user_url

What is the prototype of a method that accepts this kind of parameters? How do I read them?

Best Answer

If you pass paramaters to a Ruby function in hash syntax, Ruby will assume that is your goal. Thus:

def login_success(hsh = {})
  puts hsh[:msg]
end