From: "Stephan Kämper" Date: 2007-11-02T17:20:27+09:00 Subject: Re: What the hell is the => operator? Am Freitag, den 02. November 2007 um 09.06 Uhr schrieb Just Another Victim of the Ambient Morality : > I've seen this in some ruby code but I have no idea what is going on. >I'd do a google search on it but... I don't search for '=>' and I don't know >how to describe it in english so that the context will be this! > I've seen this operator used in, what seems to me, to be totally bizarre >contexts. As far as I know, it's only used in hash definitions. However, >it's used in both Rails and scRUBYt. It looks something like this: > > >method_call :symbol => false do > # do something here >end > >another_method random_var, :symbol => :other_symbol do > # do something else >end > > > Can someone explain to me what is going on here? It's mostly 'syntactic sugar'. In Ruby you can leave the curly braces {} in a method call away in case the last values form a hash. For example: method_call( param_1, param_2, :sym1 => 'something', 'another_key' => :another_value ) Note that you're not limited to symbols as hash keys. The following examples are esentially the same: method_call( :symbol => false ) do # do something here end another_method( random_var, :symbol => :other_symbol ) do # do something else end method_call( { :symbol => false } ) do # do something here end another_method( random_var, { :symbol => :other_symbol } ) do # do something else end '=>' is used to point from a hash key to its value. Happy rubying Stephan