Question

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?

Was it helpful?

Solution

[].select(&give_block) 

will do the trick

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top