Glenn Smith
4/10/2005 7:08:00 PM
Perfect! Thanks muchly
Glenn
On Apr 10, 2005 7:18 PM, Saynatkari <ruby-ml@magical-cat.org> wrote:
>
> Le 10/4/2005, "Glenn Smith" <glenn.ruby@gmail.com> 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!
>
>
--
All the best
Glenn
Aylesbury, UK