From: Rich Kilmer Date: 2002-08-08T22:54:54+09:00 Subject: RE: Named paramters again This is an excellent point Nobu...thank you for pointing it out. It IS safer and does not confuse the look of the code much (it actually makes it clearer from my perspective). -rich > -----Original Message----- > From: nobu.nokada@softhome.net [mailto:nobu.nokada@softhome.net] > Sent: Thursday, August 08, 2002 6:29 AM > To: ruby-talk ML > Subject: Re: Named paramters again > > Hi, > > At Thu, 8 Aug 2002 08:49:56 +0900, > Rich Kilmer wrote: > > In Ruby you could (as easily) do this instead of the 20 param thing. > > > > class Widget > > attr_accessor :x, :y, :z > > def initialize(&block) > > @x=0 > > @y=0 > > @align=:center > > # ... lots of other params > > instance_eval &block if block_given? > > end > > end > > > > Widget.new {@align=:left} > > > > Which is how I solved it for my GUI abstraction layer. > > I don't guess that it's good habit to instance_eval block > created in other scope, since changing the receiver in > invisible place from the definition point often causes > confusion. Rather, I'll suggest yielding with "self". > > class Widget > attr_accessor :x, :y, :z, :align > def initialize() > # same as above... > yield self if block_given? > end > end > > Widget.new {|w| w.align = :left} > > -- > Nobu Nakada