From: kendear Date: 2007-09-16T09:40:41+09:00 Subject: Re: Newbie help ------=_Part_3573_4397088.1189903240925 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/15/07, Ali Koubeissi wrote: > > Hey, I've started with Ruby two days ago, and I have some questions. > > 1- What's the use of Symbols? I've read that symbols are (Symbols are > lightweight strings. Usually, symbols are used in situations where you > need a string but you won't be printing it to the screen.), however I > cannot understand how to use them, and so I tried to read some examples > and I got this: you can think of symbol as string... except symbol is always identical if it has the same name... i think you can think of it as: when Ruby see a new symbol, it gives it an ID of 1 then next time it sees a different label, it gives it an ID of 2 so when a symbol is used as a hash key, it is just using "1" as the ID instead of a string... which will save the time of processing the string and help the program run faster... although internally, i wonder whether it is 1, 2, 3, 4, etc, or the pointer to the symbol object like 0x32fe117F which is still a unique ID.... ------=_Part_3573_4397088.1189903240925--