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