A WEBIE with his own style ....

Thursday, January 19, 2006

:Symbols in Ruby

One thing that kept bugging me when I started using RoR (Ruby on Rails) was the expressions preceded by a colon (:id, :link). After little googling I found out these are called Symbols and it's does mainly save space by acting as an identifier for a set of strings that has to be used on several times in a code (There are other usages such as defining a method name). 
Definition for symbols in the book Programming Ruby,
A Ruby symbol is the internal representation of a name. You construct the symbol for a name by preceding the name with a colon. A particular name will always generate the same symbol, regardless of how that name is used within the program.
So :Symbols is no longer a queer, afterall it's a helper.


Post a Comment

<< Home