From: Dossy Date: 2002-06-14T03:52:05+09:00 Subject: Re: procs and blocks On 2002.06.14, Evan Martin wrote: > On Thu, Jun 13, 2002 at 08:20:11PM +0900, Dirk Detering wrote: > > This seems to indicate me that 'named parameters' > > are missing, which are possible in Python > > (and do attract me)? > > > > With that the last line would read: > > err (b=a) > > > > Ok, in Ruby there should be an alternative syntax, > > as this one causes another result (and is supposed to). > > You can simulate named parameters with a hash: > > def foo(params) > p params[:rar] > p params[:blah] > end > > foo(:blah => "hello", :rar => "meow") > > but yes, I agree Python is nicer in this respect. Does Ruby really automagically coerce that parameter list into a Hash? PoLS for me would have been to write: foo( { :blah => "hello", :rar => "meow" } ) The shorthand you wrote where the parameters automagically get coerced into a Hash is definitely the desirable behavior, but at first glance I'd have to ask: "what kind of Object will the #foo method be receiving?" and guess ... (I guess I can take out all those unecessary {}'s in my code now ... I probably should have tried without to see if it'd work, but then I'd be surprised if it did ...) What about this, though: foo :blah => "hello", :rar => "meow" Does that work? Yes, it does, cool. But: foo { :blah => "hello", :rar => "meow" } That doesn't work. (I can see why: am I passing a block, or a Hash object?) This is the error I get (on Ruby 1.6.7): irb(main):020:0> foo { :blah => "hello", :rar => "meow" } SyntaxError: compile error (irb):20: parse error foo { :blah => "hello", :rar => "meow" } ^ from (irb):20 So, is best-practice to let the Ruby parser do the magic and create a new Hash array without using the {} notation? -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)