Ruby Symbols

2012 May 14 at 07:28 » Tagged as :ruby, dbi,

In my learn Ruby in 48 hours project, I left one black box unopened, Now I am attacking it with a hammer and chisel. It's those tiny little ':' symbols scattered all over ruby code that's bugging me. You find them in many different tutorials and books with little or no explaination.

Sample codes that contain ':' are a plenty in The Humble Little Ruby Book, but it doesn't explain what these are. Someone had even popped a question about it at Stackoverflow, and coincidentally he has cited the same example I used in an earlier post.

So what the hell are those things anyway? They are symbols (couldn't they have at least come up with a more imaginative name?). Ok so WTH is a symbol? according to RandomHacks they are memory leaks but that writer gives 12 other explanations as well. Troubleshooters.com says "It's a string. No it's an object. No it's a name."

Perhaps things would become clearer if we figured out what's the equivalent in PHP, but there isn't an equivalent! How about Python? There isn't one either. Thankfully a good enough explanation can be found on a SitePoint Ruby on Rails Tutorial: "In Ruby, a Symbol is a simple textual identifier. Like a String, a Symbol is created using literals; the difference is that a Symbol is prefixed with a colon :"