Surya
Surya

Reputation: 4972

passing in block to method in Ruby

I would like to pass in an generated(higher order function) to a method to a ruby method . Something like this

 [].select give_block

  def give_block 
    lambda { |e| e > 1 }  
  end

I get an error saying

"wrong number of arguments (1 for 0)"

How could i accomplish something like this?

Upvotes: 2

Views: 296

Answers (1)

lucapette
lucapette

Reputation: 20724

[].select(&give_block) 

will do the trick

Upvotes: 6

Related Questions