开发者

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?


[].select(&give_block) 

will do the trick

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜