代码块是指:
def callBlock
yield
yield
end
callBlock { puts "In the block" } #this is the block
最佳答案
b = lambda { puts "this is the block" }
callBlock &b
或
b.call
带参数:
def call_block_name
yield "Dave"
yield "Mary"
end
b = lambda { |s| puts "this is block #{s}" }
call_block_names &b
和
b.call("sam")
关于ruby-on-rails - 如何定义一个代码块一次使用多次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/613238/