3 ms·
Its a fine article. I always found that some people immediately "get" what a symbol is and others take a while. The way I used to teach symbols, not in ruby,
by jhancock 18y ago
Its a fine article. I always found that some people immediately "get" what a symbol is and others take a while.
The way I used to teach symbols, not in ruby, but in some "other object language" that had such animals is to have people play with their tools. In such other languages we had these visual tools to inspect and see references between objects. One of the first things you learn is to understand that objects just have "slots" which are referenced through variable names (or indexes) and those slots simply hold pointers to other objects.
Now, once you get that, you can visually explore what a symbol is. Its an "immutable" object sitting in a global table. When you inspect these symbol objects, you see they map to a unique integer value (hey cool, like constants in C!!). And so on goes your understanding...the "name" of a symbol is an array of characters. Open an inspector on the symbol #hello and the symbol #goodbye and you can discover visually that the character $e that each different symbol contains points to the same exact character object in the system. There is only one character $e in the entire VM!!
ok, I probably went too far. Anyway, the point is if you had the right tools to explore, people just need a push in the right direction and their understanding will deepen on its own.
I wish ruby had such visual tools...