开发者

passing in block to method in Ruby

开发者 https://www.devze.com 2023-04-03 03:51 出处:网络
I would like to pass in an generated(higher order function)to a method to a ruby method . Something like this

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?


[].select(&give_block) 

will do the trick

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号