From: Frank Church Date: 2007-06-26T18:27:16+09:00 Subject: Re: Some help needed with understanding ruby hashes Frank Church wrote: > > If a ruby hash rubyhash has a key such as "hashkey" is there a way of > retrieving the value by the expression rubyhash["hashkey"] ? > > It only seems logical that is rubyhash.has_key?("hashkey") returns true > rubyhash["hashkey"] should return a value, but it always gives an error. > > I know the same can be achieved via with rubyhash.values_at("hashkey") > but it appears so inelegant to me. > > I am trying to create an erb template which will use the hash keys here > such as directory1 directory2 for each directory and the for each > directory use hash key s such as directory, archivename etc, but I find > values_at rather inelegant. > > I sorely hope there is some aspect to ruby hashes syntax that I am > missing. > I tracked the error, I was testing the using the concatenating strings without using to_s in the code. ie. puts "hashkey value is " + rubyhash["hashkey"] instead of "hashkey value is " + (rubyhash["hashkey"]).to_s Regards Frank -- Posted via http://www.ruby-forum.com/.