摘要:
$res = "__"def lamb(&lamb) 3.times do puts $res=lamb.call end puts "-------at the end of lamb() : #{$res}"enddef lamb_test lamb { return puts " return in lamb() " } puts "--------at the lamb_test() end"enddef bl 3.times do puts $res= yield end puts " 阅读全文
摘要:
Ruby 之 Block, Proc, LambdaBlockBlock 不是对象,是Ruby的语言特性,近似于闭包(Closure)。范例:def meth res= yield "Block called returns #{res}"endputs methdo next “next_value” end #Block called returns next_valueputs methdo break “break_value” end # break_vcowcuo错误哦aluedef my methdo return “reutnr_value” endendp 阅读全文