each_with_object

enum.each_with_object(obj) { |(*args), memo_obj| ... } â obj
enum.each_with_object(obj) â an_enumerator
Instance Public methods

Iterates the given block for each element with an arbitrary object given, and returns the initially given object.

If no block is given, returns an enumerator.

evens = (1..10).each_with_object([]) { |i, a| a << i*2 }
#=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
doc_ruby_on_rails
2015-04-04 23:56:16
Comments
Leave a Comment

Please login to continue.