ruby methods that either yield or return Enumerator

后端 未结 4 705
死守一世寂寞
死守一世寂寞 2021-01-31 03:47

in recent versions of Ruby, many methods in Enumerable return an Enumerator when they are called without a block:

[1,2,3,4].map 
#=>         


        
4条回答
  •  你的背包
    2021-01-31 04:30

    Another approach might be:

    class Array
        def double(&block)
            map {|y| y*2 }.each(&block)
        end
     end
    

提交回复
热议问题