From: Josh Cheek Date: 2011-07-25T17:52:23+09:00 Subject: Re: Please give simple example of when to use symbols --f46d043be13af117bd04a8e0ee3d Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jul 25, 2011 at 2:20 AM, Kaye Ng wrote: > I'm still a bit confused on whether to use strings or symbols in certain > situations. They produce the same results, although strings take up > more memory, which I'm not sure how or why exactly. > > I think when people say they take up more memory, they mean that symbols don't get garbage collected. So if you make one, it is around until your program ends. This could be a problem if you were generating them dynamically, you could eat up all your memory. When do you normally use a symbol instead of a string? > > Check out the first 5 minutes of Ruby Kickstart Session 3 ( http://ruby-kickstart.com/#session3) For some examples, you can watch past that. On Mon, Jul 25, 2011 at 2:51 AM, 7stud -- wrote: > > > When do you normally use a symbol instead of a string? > > The easiest thing to do is never use symbols--symbols aren't worth the > waste of time trying to understand them. Although, the idiotic > explanations I read are pretty hilarious. If you understand pointers, > then symbols are easy to understand. If you don't know what a pointer > is, then you won't ever understand symbol. You can rub all the crystals > you want and mediate on "the essence" of the thing, but you won't have > any idea what you are dealing with. > > It's just an immutable string that doesn't get garbage collected, and every symbol of a given name (text value) is the same object. --f46d043be13af117bd04a8e0ee3d--