# Problem accessing hash table

**URL:** <https://www.ruby-forum.com/t/problem-accessing-hash-table/138700>\
**Category:** Ruby\
**Created:** [May 26, 2008, 11:18pm UTC](https://www.ruby-forum.com/t/problem-accessing-hash-table/138700 "2008-05-26T23:18:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [May 26, 2008, 11:18pm UTC](https://www.ruby-forum.com/t/problem-accessing-hash-table/138700/1 "2008-05-26T23:18:20Z")

</div>

Hi,

I am facing the following problem, when using the following code  
snippet:

c = []  
c.push({:name =\> ‘xyz’, :class =\> ‘m70’, :title =\> ‘yes’})

Now, puts c gives me the output as classm70namexyztitleyes

My Aim is to access the :name attribute of the hash table that is being  
pushed into the c array. I tried the following:

puts c[:name] , gives an error - p046hashes.rb:10:in `[]’: Symbol as  
array index (TypeError)  
from p046hashes.rb:10

Can anyone help as to how I can access the value of the hash table  
defined in the array?

Thanks,  
Anukul

---

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [May 26, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/problem-accessing-hash-table/138700/2 "2008-05-26T23:57:24Z")

</div>

On Mon, May 26, 2008 at 4:17 PM, Anukul S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## My Aim is to access the :name attribute of the hash table that is being Anukul

In your example, you have a Hash instance as an element of an Array  
instance. That doesn’t sound like what you probably want. But if it  
is, and since it is the first element in your array c, you can get  
that hash with c[0].

puts c[0][:name]

hth,  
Todd
