# rails array.each returning array?

**URL:** <https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884>\
**Category:** rubyonrails-talk\
**Created:** [February 27, 2009, 6:30pm UTC](https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884 "2009-02-27T18:30:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 27, 2009, 6:30pm UTC](https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884/1 "2009-02-27T18:30:48Z")

</div>

i am having a problem with a current piece of code, and it seems like the result for each on an array might be the culprit.

according to everything i have seen before, this should work:

&nbsp;&nbsp;&nbsp;a = ["a", "b", "c"] &nbsp;&nbsp;&nbsp;a.each {|x| print x, " -- " }

should produce:

&nbsp;&nbsp;a -- b -- c --

but i am getting:

> > a = ["a", "b", "c"]

=\> ["a", "b", "c"]

> > a.each {|x| print x, " -- " }

a -- b -- c -- =\> ["a", "b", "c"]

does anyone know where the =\> ["a", "b", "c"] is coming from?

specifically, i am trying to run:

def self.show\_pending\_users &nbsp;&nbsp;&nbsp;&nbsp;self.find(:all, :conditions =\> "pending\_role is not null").each {

> x\> "#{x.login}" }

&nbsp;&nbsp;end

where i expect to get a an array of x.login back.. but i am getting back an array of all the objects ...

any ideas?

thanks!

---

<div class="post-metadata">

**Author:** ![Starr\_Horne](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Starr\_Horne](https://discuss.rubyonrails.org/u/Starr_Horne)\
**Post date:** [February 27, 2009, 6:35pm UTC](https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884/2 "2009-02-27T18:35:16Z")

</div>

> does anyone know where the =\> ["a", "b", "c"] is coming from?

It's only doing that in the console, because the return value of each is the array you passed it. If you run this code outside of irb, you won't see it.

SH

---

<div class="post-metadata">

**Author:** ![Mauricio\_Linhares1](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@Mauricio\_Linhares1](https://discuss.rubyonrails.org/u/Mauricio_Linhares1)\
**Post date:** [February 27, 2009, 6:35pm UTC](https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884/3 "2009-02-27T18:35:52Z")

</div>

What you want is map, not each (the ruby-doc is always your friend):

def self.show\_pending\_users &nbsp;&nbsp;&nbsp;self.find(:all, :conditions =\> "pending\_role is not null").map {|x| "#{x.login}" } end

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 27, 2009, 6:52pm UTC](https://discuss.rubyonrails.org/t/rails-array-each-returning-array/39884/4 "2009-02-27T18:52:27Z")

</div>

Maurício Linhares wrote:

> What you want is map, not each (the ruby-doc is always your friend):

ah!

this ended up working perfectly..

thanks so much everyone...
