# Attribute\_names and/or values?

**URL:** <https://www.ruby-forum.com/t/attribute-names-and-or-values/91050>\
**Category:** Rails\
**Created:** [April 4, 2007, 3:30am UTC](https://www.ruby-forum.com/t/attribute-names-and-or-values/91050 "2007-04-04T03:30:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 4, 2007, 3:30am UTC](https://www.ruby-forum.com/t/attribute-names-and-or-values/91050/1 "2007-04-04T03:30:32Z")

</div>

Hi rubyists,

I’m clunking around with this problem. I want to return an array of  
values from each record in my database table.  
I have this so far:  
@t = Table.find(:all)

@t.each do |k|  
k.attributes  
end

the method attributes returns a hash and attribute\_names returns an  
array or the keys. Is there a method that returns an array of the  
values?

Thanks,  
Bryce

---

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 4, 2007, 3:45am UTC](https://www.ruby-forum.com/t/attribute-names-and-or-values/91050/2 "2007-04-04T03:45:33Z")

</div>

May be can try this:

@t.map do |k|  
k.attributes.values  
end

# return [[value1, value2, value3], [value1, value2, value3] …]

Herry

---

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 4, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/attribute-names-and-or-values/91050/3 "2007-04-04T20:05:50Z")

</div>

Thanks a lot, the code worked great after a couple of tweaks to the  
code above it.

Any reason that

@t.map do |k|  
k.attributes.values  
end

works and

@t.each do |k|  
k.attributes.values  
end

(map vs. each) doesn’t work?
