先不多言,贴个例子来看看
def run_a_yield
xyz = "This is xyz"
yield
puts "==>>" + xyz
end
#yield a block
run_a_yield{
# puts "==>>" + xyz #Notice we cann't use the field defined in other scope!!!
puts "fantaxy is here!"
}
def a_method
puts "This is a_method"
end
#yield a method
# run_a_yield a_method # we cann't yield a block by this!!!
run_a_yield {a_method}
O
O
O
+
O
O
O