David A. Black wrote:
> Except....
> 
>    >> [1,2,3].each.with_object("hi!").map{|v| v + 3 }
>    => [4, 5, 6]
> 
> The map is only binding one of the arguments, and the argument to
> with_object is being ignored. (The 3 is hard-coded in the block.)
> 

 I think my examples show that pretty clearly:

> #<Enumerator:0x0e72bc>
> 
> What's "in" that enumerator?
> 
> e = [1,2,3].each.with_object(3)
> 
> e.each do |x, y|
>   puts "#{x.inspect} #{y.inspect}"
> end
> 
> --output:--
> 1 3
> 2 3
> 3 3
> 
> As you can see, the enumerator is returning each element of the array 
> along with with_object's argument: 3.
> 
> The next call in the method chain is map():
> 
>>>> [1,2,3].each.with_object(3).map{|v|v+3}
> 
> map takes the value(s) it is sent, converts the value(s), then stores 
> the converted value(s) in an array, then the array is returned as the 
> final result of the call to map():
> 
> result = [1,2,3].each.with_object(3).map do |v, w|
>   puts "#{v} #{w}"
>   v + 3
> end
> 
> p result
> 
> --output:--
> 1 3
> 2 3
> 3 3
> [4, 5, 6]
> 

In both examples, I tried to demonstrate that the op was discarding the
second argument yielded to the map block.
.
.
.
.
.
.
.
-- 
Posted via http://www.ruby-forum.com/.