From: "Berger, Daniel" Date: 2005-08-09T00:14:11+09:00 Subject: Re: polymorphism and/or named parameters: the ruby way? > -----Original Message----- > From: Stephan Mueller [mailto:d454d@web.de] > Sent: Saturday, August 06, 2005 12:01 PM > To: ruby-talk ML > Subject: polymorphism and/or named parameters: the ruby way? > > > Hello, > > i am kind of a newbi, please forgive me if i am asking stale > questions. > > I want to adjust the initialization of an object according to > the parameters given to new. A typical idiom for constructors is to do "yield self if block_given?", which I prefer over hash based arguments. For example: class Foo attr_accessor :bar, :baz, :zap def initialize yield self if block_given? end end foo = Foo.new do |f| f.bar = "hello" f.baz = 5 f.zap = "world" end Many thanks to Hal Fulton's "The Ruby Way" for teaching me this trick. :) Regards, Dan