I am confused by the two different syntaxes. Both work just fine and there is not a difference in the outcome, so which? And why two methods? What''s the bigger picture? Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 31-Aug-06, at 10:44 PM, Jeremy Cowgar wrote:> I am confused by the two different syntaxes. Both work just fine and > there is not a difference in the outcome, so which? And why two > methods? What''s the bigger picture?The arguments are converted to symbols (whether they are strings, or symbols to begin with), so it doesn''t matter. I favour the symbol version because it looks prettier. irb(main):003:0> :table_name.to_sym == "table_name".to_sym => true /Jeff -- http://re.visioni.st http://quotedprintable.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
the bigger picture is symbols vs strings. the quick answer: symbols and strings are pretty much the same for the most part. the big difference is at the memory level. every time you use a string, no matter if it''s been used before, memory is allocated as it''s a new instance. not so with symbols. ex: irb(main):003:0> a = :foo => :foo irb(main):004:0> b = :foo => :foo irb(main):005:0> a.object_id => 3756302 irb(main):006:0> b.object_id => 3756302 irb(main):007:0> x = "foo" => "foo" irb(main):008:0> y = "foo" => "foo" irb(main):009:0> x.object_id => -604402436 irb(main):010:0> y.object_id => -604412996 notice that the object_ids for a and b are the same, but for x and y they are different. so if you use the same string over and over, especially in parameters passed in Rails methods, you''re going to be consuming more memory than if you used symbols. for more detailed explanations, google for ''ruby symbols'' Chris On 8/31/06, Jeremy Cowgar <jeremy-gpWmyxsr1AXQT0dZR+AlfA@public.gmane.org> wrote:> > I am confused by the two different syntaxes. Both work just fine and > there is not a difference in the outcome, so which? And why two > methods? What''s the bigger picture? > > Jeremy > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> symbols and strings are pretty much the same for the most part. the > big difference is at the memory level. every time you use a string, > no matter if it''s been used before, memory is allocated as it''s a new > instance. not so with symbols.None of this really matters for a migration. I tend to use strings because thats what my textmate bundle uses. Though I should change it, symbols turn a really neat blue color. -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---