# About 1.8.7 Array#map! without a block

**URL:** <https://www.ruby-forum.com/t/about-1-8-7-array-map-without-a-block/139432>\
**Category:** Ruby\
**Created:** [June 3, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/about-1-8-7-array-map-without-a-block/139432 "2008-06-03T21:51:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eustaquio\_STaQS\_Ran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/34f0e0/32.png) [@Eustaquio\_STaQS\_Ran](https://www.ruby-forum.com/u/Eustaquio_STaQS_Ran)\
**Post date:** [June 3, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/about-1-8-7-array-map-without-a-block/139432/1 "2008-06-03T21:51:35Z")

</div>

Hi there.

I was wondering how to use Array#map! with a block. On the usual way, we  
have

irb(main):001:0\> a = [1,2,3]  
=\> [1, 2, 3]  
irb(main):002:0\> a.map! {|i| i\*2}  
=\> [2, 4, 6]

Now with 1.8.7 we have:

irb(main):003:0\> e = a.map!  
=\> #Enumerable::Enumerator:0xb7db015c  
irb(main):004:0\> e.next  
=\> 2  
irb(main):005:0\> a  
=\> [#\<Generator:0xb7d9b9dc @queue=[4],  
@cont\_endp=#Continuation:0xb7d9b1a8, @index=1,  
@block=#Proc:0xb7da7ffc@/usr/local/lib/ruby/1.8/generator.rb:71,  
@cont\_yield=#Continuation:0xb7d9aed8, @cont\_next=nil\>, 4, 6]  
irb(main):006:0\> a.size  
=\> 3

I got an Enumerable::Enumerator with a.map! and then the first call to  
e.next returned me the first “a” element, 2. Ok, two questions:

1 - Since I created the Enumerable::Enumerator with map!, I presume it’s  
used on some way to change the elements on “a”, so what should I use  
with e.next to change the value, say, multiplying by 2 as on the first  
case and have a [4,8,12] array on the end?

2 - Why I get a Generator on “a” elements when I just call e.next? The  
cause it’s what I’m missing to use with next, as asked on the first  
question?

Thanks!
