From: "Jesús Gabriel y Galán" Date: 2009-01-13T06:01:16+09:00 Subject: Re: what's the rules re whether a Hash can use either a Symbol or String to reference the value??? On Mon, Jan 12, 2009 at 9:50 PM, Greg Hauptmann wrote: > Hi, > Getting confused with Hashes a bit. It seems sometimes I can use both a > Symbol or a String to get the value back, but other times the Symbol doesn't > work. Is there any rule re how to remember how Hash handles setting and > getting values uses Symbol / String? > > e.g. hash_variable[:amount] versus hash_variable["amount"] > > e.g. hash_var = {:amount => 10}, versus hash_var = {"amount" => 10) In general, a hash uses eql? to know if a key matches the one you are asking for. So in general a Symbol and it's String counterpart are not the same key in a hash. There are different implementations that allow using Strings / Symbols to refer to the same key. Search for HashWithIndifferentAccess or something like that. I think Rails uses something similar, IIRC. Maybe your confusing comes from the different behaviour when you are using Rails vs non-Rails? Jesus.