On 10.06.2007 08:53, Erwin Abbott 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

Why do you need x here?  Do you need to pass it around?  Can you show a 
bit more of the picture?

> 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.

There is no other compatible way than to explicitly pass a lambda / proc 
as argument in 1.8.x:

irb(main):003:0> f = lambda {|a,b| 5.times { a = b[a] }; a }
=> #<Proc:0x7ff7a1c8@(irb):3>
irb(main):005:0> f[0, lambda {|x| x+1}]
=> 5

Kind regards

	robert