On Aug 8, 2005, at 12:21 PM, Eric Mahurin wrote:

> --- "Berger, Daniel" <Daniel.Berger / qwest.com> wrote:
>>
>> 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
>>
>
> What's the advantage of this over:
>
> foo = Foo.new
> foo.bar = "hello"
> foo.baz = 5
> foo.zap = "world"

Perhaps you want to create and use an object without even assigning  
it to a variable:

Message do |mes|
     # build message here...

     mes.send
end

James Edward Gray II