【发布时间】:2015-04-05 04:25:22
【问题描述】:
我试过这段代码:
def m
return yield if block_given?
"no block"
end
puts m do
x = 2
y = 3
x*y
end
为什么输出是“无块”? 我将块构建到 m 的方式有什么问题? {"testing"} 会起作用。
【问题讨论】:
-
这已经在Ruby Block Syntax Error、Code block passed to
eachworks with brackets but not withdo-end(ruby)、Block definition - difference between braces anddo-end?、Ruby multiline block withoutdoend、Usingdoblock vs brackets{}、What is the difference or value of these block coding styles in Ruby?、...中得到解答。
标签: ruby