From: Sharon Phillips Date: 2007-07-14T21:48:33+09:00 Subject: Re: attr_writer and hash > Hi, > > class Test > attr_writer :username, :password > def initialize > h = {:username => 'user', :password => 'pass'} > end > end > > t = Test.new > p t.h[username] > > > I am trying to access a hash key after instantiating the Test class, > but I am having a slight problem. > > Could someone please direct me? > > Thanks > > Aidy Hi Aidy, It looks like you're mixing two different ways of getting at username and password here. Here are two separate approaches you could try class Test attr_accessor :username, :password def initialize @username= 'user' @password= 'pass' end end t= Test.new puts t.username puts t.password class Test2 attr_accessor :details def initialize @details= {:username => 'user', :password => 'pass'} end end t= Test2.new puts t.details[:username] puts t.details[:password] I think the problem with your code is a missing colon before username. Should be p t.h[:username] Cheers, Dave