I move into WordPress from Blogger.
Protean [Henggen-Zizhai]
Nov 16, 2008
Nov 14, 2008
Difference between "do end" and "{ }" in Ruby
"{ }" has a stronger connection than "do end".
foobar is called with block.
b is called with block.
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
Nov 13, 2008
Nov 12, 2008
Subscribe to:
Posts (Atom)