def foobar a, b
if block_given?
yield a, b
else
puts a * b
end
end
foobar is called with block.
foobar 2, 3 do |a, b|
puts a + b #=> 5
end
b is called with block.
def b
yield
end
foobar 2, b { 3 } #=> 6
I'm a Japanese programmer. I write about C#, Ruby and JavaScript.
No comments:
Post a Comment