More explicitly, consider this code:
def use_block
yield
end
def foo(x)
use_block { return x*x }
2*x
end
def store_block(&block)
$stored_block = block
end
def bar(x)
store_block { return x*x }
2*x
end
puts foo(7)
puts bar(11)
puts $stored_block.call
It produces the following output:
49
22
lambda-do.rb:15:in `bar': unexpected return (LocalJumpError)
from lambda-do.rb:21:in `call'
from lambda-do.rb:21
The foo(7) (use immediately) case returns the result from the block (x*x, or
49) and never gets to the last bit (the 2*x); the bar(11) case returns the
2*x but errors out when you try to call the stored block.
-- Markus
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.