From: Rob Biedenharn Date: 2007-07-12T05:39:44+09:00 Subject: Re: question about passing hashes to an action On Jul 11, 2007, at 3:53 PM, Max Williams wrote: > It seems to be a common tactic in ruby to pash what looks like a > key-value pair, in which the key is a symbol, to an action. For > example > with the rails action 'render', we say > > render :text => "Hello world!" #(from dhh's famous blog tutorial) > > Can anyone explain to me what's happening here, ie what's being passed > in? Is it the equivalent of having a (say) java method that takes a > string and saying > render("Hello world!")? > > I've been trying to experiment with my own classes with this > tactic, but > i'm new to ruby and can't get an example of the above working. The trailing set of key => value pairs are turned into a hash passed as the final argument to a method. The fully punctuated version of that is: render({:text => "Hello world!"}) You'll often see methods defined as: def my_method(arg1, arg2, options={}) when there is an optional set of options that can be passed in as a hash. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com