From: Saynatkari Date: 2005-04-11T03:18:22+09:00 Subject: Re: Symbols... Le 10/4/2005, "Glenn Smith" a �crit: >Nope, still not entirely sure I *get* symbols. > >I'm writing stuff in rails at the moment, and *seem* to have free >choice as to whether to use something like: > >@params[:year] > >or > >@params['year'] > >What's the difference? Coming from mainly a VB and PL/SQL (and rarely >'C') I'm not sure there is an equivalent in these languages? Just not >sure I get them... Symbols are immutable, unlike Strings. The biggest difference, however, is the conceptual one. Wherever you need to use a descriptive value for a variable (basically wherever you would use a string in other languages) you have the choice of using a String or a Symbol; for you, the programmer, both can convey immediate information about the value (:flag_set or 'flag set' is clearer than 1) and they are especially useful as Hash keys. Symbols are slightly more lightweight than Strings and, along with them being the 'Ruby Way', that is the main reason to use them. My rule of thumb is to use Symbols anytime a string representation is needed but I will not need to modify the string or output it to a user. >Help? >Glenn E -- No-one expects the Solaris POSIX implementation!