call method with block parameter:
two syntaxes:
1. { }
this is useful for one line
2. do end
this is useful for multiple line
ex:
["a", "b"].each do |i|
puts "#{i}"
end
the element between | | refers to each element in the array
use &
ex:
class Array
def test( &arg)
find_all( &arg)
end
end
pass proc parameter to a method received block
ex:
a=lambda{ puts "abc"}
test(&a)
沒有留言:
張貼留言