我有以下
Ruby代码:
- # func1 generates a sequence of items derived from x
- # func2 does something with the items generated by func1
- def test(x,func1,func2)
- func1.call(x) do | y |
- func2.call(y)
- end
- end
- func1 = lambda do | x |
- for i in 1 .. 5
- yield x * i
- end
- end
- func2 = lambda do | y |
- puts y
- end
- test(2,func2) # Should print '2','4','6','8',and '10'
当然,这不起作用.
- test.rb:11: no block given (LocalJumpError)
- from test.rb:10:in `each'
- from test.rb:10
- from test.rb:4:in `call'
- from test.rb:4:in `test'
- from test.rb:20