On 6/10/07, Erwin Abbott <erwin.abbott / gmail.com> wrote: > I'd like to do something like: > > x = lambda do |*args| > if args.size == 5 > # call another block > yield *args.map{|x| x.gsub(/es$/, '') } > end > end > > x.call(*%w[cats dogs ones twos threes]) do |*words| > puts words.last # output: thre > end > > But x.call(..) { block } raises LocalJumpError: no block given. I'm > not sure how to pass a block because it seems #call doesn't pass it > on. Sorry if this is a common question, but I'm having a hard time > searching for help because "passing block to lamda call" appears in > every page about the basics of closures. > > I see lamda {|&block| ... } is added in ruby 1.9, but I'd like to be > compatible with 1.8 too. > > class Proc def bcall(*args,&block) self.call(*args.concat([*block])) end end x_y = lambda {|data,proc| proc.call(data) if data.is_a? String } x_y.bcall("hello") {|data| puts data.succ } It's a hack, but it works. -- Chris Carter concentrationstudios.com brynmawrcs.com