From: Mick Macamhlaoibh Date: 2007-08-14T10:11:17+09:00 Subject: Can a lambda or Proc object yield a value to a block? I've searched quite a bit on the web and through "Programming Ruby - the Pragmatic Programmer's Guide" and I can't find a satisfactory answer to the question: Can a lambda or Proc object yield a value to a block? For example when I try this yieldArg = lambda {|arg| yield arg} yieldArg.call(23) {|y| puts("y="+y.to_s)} in Interactive Ruby I get "LocalJumpError: no block given" So I try yieldArg = lambda {|arg| puts "no block given" unless block_given? ; yield arg} to print some indication of whether the block really has been "given" and I get no block given LocalJumpError: no block given So then I try to wrap the block in a lambda and pass it as a param putsY = lambda {|y| puts("y="+y.to_s)} yieldArg.call(23) {|y| puts("y="+y.to_s)} yieldArg.call(23, &putsY) but with the same negative result. So can a lambda or Proc object yield a value to a block? If so, how is it done? Thanks in advance. Interactive Ruby session shown below. irb(main):001:0> yieldArg = lambda {|arg| yield arg} => # irb(main):002:0> yieldArg.call(23) {|y| puts("y="+y.to_s)} LocalJumpError: no block given from (irb):1 from (irb):2:in `call' from (irb):2 irb(main):003:0> yieldArg = lambda {|arg| puts "no block given" unless block_given? ; yield arg} => # irb(main):004:0> yieldArg.call(23) {|y| puts("y="+y.to_s)} no block given LocalJumpError: no block given from (irb):3 from (irb):4:in `call' from (irb):4 irb(main):005:0> putsY = lambda {|y| puts("y="+y.to_s)} => # irb(main):006:0> yieldArg.call(23, &putsY) no block given LocalJumpError: no block given from (irb):3 from (irb):6:in `call' from (irb):6 irb(main):007:0> -- Posted via http://www.ruby-forum.com/.