假设我有以下代码:
def a(n, m, &block)
yield if block_given?
end
def a
# My question is here. When a is called, block might be or might not be
# given. Below line is obvious wrong. How to call b and properly pass
# block to b?
b(1, 2, &block)
end
a # call a without block
a { # call a with a block
puts "in block"
}
block
的方法,否则在那里它是未定义的。 - Andrew Marshalla
使得第一个定义的a
变得毫无意义。你没有展示出b
是什么。不清楚你在做什么。 - sawa