[Rails] Re: Learning About Symbols

2013-07-12 Thread Timster
Symbols are used all the time in Ruby/Rails when sending methods. For example, look at the following method call: instance.do_stuff(:foo => :bar, :answer => 3) What you are actually sending to the do_stuff method is a hash that looks like the following: { :foo => :bar, :answer => 3 } For t

[Rails] Re: Learning About Symbols

2013-07-12 Thread Peter
> Are these true or false? >> yaml['config'] == yaml[:config] >> yaml['config']['another_setting'] == yaml[:config][:another_setting] >> > > The answer to both is false. > yaml['config'] shows me the values from the yml file. yaml[:config] doesn't. How else do you use symbols? I have read all t

[Rails] Re: Learning About Symbols

2013-07-12 Thread Peter
On Friday, July 12, 2013 12:49:11 AM UTC-7, Ruby-Forum.com User wrote: > > One reason to use Symbols is that they are immutable. When you're > passing one around as an argument or Hash key, it won't change. > Another is that multiple instances of a Symbol are the same object, > making a smalle

[Rails] Re: Learning About Symbols

2013-07-12 Thread Joel Pearson
One reason to use Symbols is that they are immutable. When you're passing one around as an argument or Hash key, it won't change. Another is that multiple instances of a Symbol are the same object, making a smaller memory footprint than Strings. A string is not a symbol. Some structures will use