So, I came across this very interesting construct called "symbols" in ruby. It is just like a variable, a name that starts with a colon - ':'
For a clear understanding I read through a lot of forums about symbols, and all I found is that this is a very confusing idea for new comers. As you can see, Ruby symbols generated a 100+ post thread on the ruby-talk@ruby-lang.org mailing list - and some of them are really heated.
Anyway, my take for now about symbols is:
In ruby, if you say, "some double quoted string" a thousand times, ruby creates different objects for it. But if you use a "Symbol"-ised reference to it, as :"Some double quoted string", it is a symbol and it is created only once. This seems to be useful in places where you create hashes.
Anyway, I agree, this is not a very satisfying explanation of Symbols(or at least their usage). But for a Ruby newbie, this should hold good enough.
No comments:
Post a Comment