Weird keyword parameters in rails

Hi, I'm very new to Ruby, and to Ruby on Rails.
I'm halfway through the pickaxe book, past all of the stuff on syntax,
and I haven't seen anything explaining the keyword parameter syntax
used extensively in rails. The syntax I mean is:

method( :keyword => "value" )

I understand how to use this, I'm just not sure where it comes from.
Am I being docile, or is this slightly weird?
Thanks

robbie

just wanted to add, can't google it as google doesn't seem to search on
non alphanumeric characters. If anyone knows how to do that in google I
would also much appreciate it (sorry this is off topic).
:slight_smile:

It's a hash with a Symbol as a parameter.

Try it in irb.

  def foo(bar)
    puts bar.class
    puts bar.inspect
  end

  foo(:keyword => 'value')

-austin

ยทยทยท

On 9/7/05, robbie <robbie.carlton@gmail.com> wrote:

Hi, I'm very new to Ruby, and to Ruby on Rails.
I'm halfway through the pickaxe book, past all of the stuff on syntax,
and I haven't seen anything explaining the keyword parameter syntax
used extensively in rails. The syntax I mean is:

method( :keyword => "value" )

I understand how to use this, I'm just not sure where it comes from.
Am I being docile, or is this slightly weird?

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

Check out p. 361 in the Pickaxe 2nd Ed. In a method call, the initial
parameters may be followed by "a list of key => value pairs. These
pairs are collected into a single new Hash object and passed as a
single parameter." In your example, "method" would get a hash argument
with 1 key-value pair.

thanks guys.
That's a clever trick. :slight_smile: