Afficher un message
Vieux 26/05/2008, 23h17   #1
Anukul Singhal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problem accessing hash table

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 as to how I can access the value of the hash table
defined in the array?

Thanks,
Anukul
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
 
Page generated in 0,04781 seconds with 9 queries