Hello --
Well, not puzzle in the fun sense -- just something I don't
understand.
I've been playing around with ways to generated a default block to
yield to. This isn't a particular great way, but I'm stuck on why it
doesn't at least work.
def thing(x, b = proc { puts "default" } )
if block_given?
yield
else
thing(x) &b
end
end
thing(1) { puts "associated block" } # => "associated block"
thing(1) # infinite loop
Somehow the "x" argument seems to be causing trouble, because this
version does what I expected:
def thing(b = proc { puts "default" } )
if block_given?
yield
else
thing &b
end
end
thing{ puts "associated block" } # => "associated block"
thing # => "default"
I'm not seeing why the first version hangs. Enlightenment welcome.
David
--
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web: http://pirate.shu.edu/~blackdav