A typical idiom for constructors is to do "yield self if block_given?",
which I prefer over hash based arguments. For example:
attr_accessor :bar, :baz, :zap
yield self if block_given?
foo = Foo.new do |f|
f.bar = "hello"
f.baz = 5
f.zap = "world"
Many thanks to Hal Fulton's "The Ruby Way" for teaching me this trick.
From: Stephan Mueller [mailto:firstname.lastname@example.org]
Sent: Saturday, August 06, 2005 12:01 PM
To: ruby-talk ML
Subject: polymorphism and/or named parameters: the ruby way?
i am kind of a newbi, please forgive me if i am asking stale
I want to adjust the initialization of an object according to
the parameters given to new.