Ruby :symbols
-
I have googled and read much on the subject of :symbols in Ruby. I strongly suspect that most of what I have read is off target, if not just plain wrong. There is some strong relationship between names in a Ruby program, and symbols, but I don't know exactly what.
Enlightenment?
-
What is off target and plain wrong?
As far as I understood symbols - they are more efficient than strings to use in for instance when you make hash keys.
I found this one an interesting read: http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol -
@thomthom said:
What is off target and plain wrong?
A question I can't answer until I can answer my own question: What's a symbol?
The link was a good one but after a too-quick read I was better versed in what you could do with symbols that what a symbol was.
In most languages there is a symbol table, under the covers. Ruby symbols seem to be bringing this capability forward, allowing us to add to the table in some way that I'm not sure I understand. Edit: make that "in some way I'm sure I don't understand." end edit
Nagging questions: if "foo" is a variable name it will be in the symbol table and :foo will be a symbol. What about "foo.bar"? Is that a :foo plus a :bar, or is it :foo.bar?
Advertisement