method
with_object
v1_9_3_125 -
Show latest stable
-
1 note -
Class: Enumerator
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (38)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
with_object(p1)
public
Iterates the given block for each element with an arbitrary object, obj, and returns obj
If no block is given, returns a new Enumerator.
Example
to_three = Enumerator.new do |y| 3.times do |x| y << x end end to_three_with_string = to_three.with_object("foo") to_three_with_string.each do |x,string| puts "#{string}: #{x}" end # => foo:0 # => foo:1 # => foo:2
Register or
log in
to add new notes.
Rubybull -
February 3, 2013 - (v1_9_3_125)
0 thanks
Difference between enum#with_object and enum#each_with_object
I found a very good post on SO - which clearly explained the difference between enum#with_object and enum#each_with_object. The link is as follows: