On 7/28/06, Ike <rxv / hotmail.com> wrote: > does the colon operator have an anolog in say, Java or C++ ? It seems to be > a reference pointer. Am i mistaken in assuming this? Thanks, Ike > > > > My take on explaining Symbols (from the "From other languages" page on new.ruby-lang.org): Many Ruby newbies struggle with understanding what Symbols are, and what they can be used for. Symbols can best be described as identities. A symbol is all about who it is, not what it is. Fire up irb and see the difference: irb(main):001:0> :george.object_id == :george.object_id => true irb(main):002:0> "george".object_id == "george".object_id => false irb(main):003:0> The object_id methods returns the identity of an Object. If two objects have the same object_id, they are the same (point to the same Object in memory). As you can see, once you have used a Symbol once, any Symbol with the same characters references the same Object in memory. For any given two Symbols that represent the same characters, the object_ids match. Now take a look at the String ("george"). The object_ids don't match. That means they're referencing two different objects in memory. Whenever you use a new String, Ruby allocates memory for it. If you're in doubt whether to use a Symbol or a String, consider what's more important: the identity of an object (ie. a Hash key), or the contents (in the example above, "george"). === So a Symbol is like an identity, or an interned string, which is used by Ruby and is available for your use internally in your program. Think of using an enum: you're really just giving names for your own good, the program doesn't care whether you key something with cars.ferrari or the number 3, as long as it's used consistently. -- - Simen