Passing inline hashes

You don't need to enclose each argument in brackets, you just need to
enclose all arguments in brackets (which is the recommended practice).

start_form_tag(
  {:action => 'blah'},
  {:class => 'css1'})

works fine.

···

-----Original Message-----
From: Brock Weaver [mailto:brockweaver@gmail.com]
Sent: Wednesday, 17 August 2005 8:55 AM
To: ruby-talk ML
Subject: Passing inline hashes

I just stumbled across an intresting problem with passing two hashes to
a method -- I was trying to pass inline hashes and ruby interpretted
them as blocks. (Makes sense looking back).

start_form_tag :action => 'blah', :class => 'css1'

This call was putting both values into the first parameter of the method
(a hash), and none in the second one. So I altered it:

start_form_tag {:action => 'blah'}, {:class => 'css1'}

Which of course ruby thinks the {} are blocks and pukes.

To explicitly tell ruby they are hashes, I had to wrap them with ().

start_form_tag ({:action => 'blah'}), ({:class => 'css1'})

Which seems awkward, as most languages use the {} syntax for inline
hashes.
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################