Hi, I''ve seen source like: params[:user] and params[''user''], or also :action => ''new'' and :action => :new, is it also possible write params["user"]? So, which are the differences between '', " and : ? when use for example : instead of others? I''ve read that, for example, in a put(''name: #{user.name}'') the output will be name: #{user.name} and with "" instead of '''' will be, for example, name: John is it right? can anyone explain me these differences? thanks :) -- Posted via http://www.ruby-forum.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?hl=en -~----------~----~----~----~------~----~------~--~---
eddie wrote:> Hi, I''ve seen source like: params[:user] and params[''user''], or also > :action => ''new'' and :action => :new, is it also possible write > params["user"]?Please read a book about Ruby itself. :yo is a symbol, ''yo'' a string. A hash could contain :yo and ''yo'' as distinct keys. But :''yo'' and ''yo''.to_sym are the same as :yo. Rails prefers symbols because they are mildly more physically efficient, and they are much more cognitively efficient.> So, which are the differences between '', " and : ? when use for example > : instead of others? > I''ve read that, for example, in a put(''name: #{user.name}'') the output > will be name: #{user.name} and with "" instead of '''' will be, for > example, name: John > is it right?That''s because #{} calls .to_s, and :yo.to_s is ''yo''. "yo" is also a string, but "" markers can interpret advanced \ escapes and #{} marks.> can anyone explain me these differences?A book about Ruby may have come with your copy of it. Curl up with that for a few hours, and your own code - between the Rails code - will improve a lot. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
thanks :) I''ve taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby I''m going immediately to study it... :) -- Posted via http://www.ruby-forum.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?hl=en -~----------~----~----~----~------~----~------~--~---
eddie wrote:> I''ve taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby > I''m going immediately to study it... :)You might also like Why''s Poignant Guide to Ruby.> Why''s it poignant?That''s the author''s pen-name; Why.> But why is his guide poignant.Yes, I have heard Why''s guide is poignant like that.> But why is it...Yep; it''s his book. Why. <and so on...> -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Look on the Ruby mailing list, I asked the same question and got a great answer. The Subject was "Symbols vs Strings" I won''t reproduce it here since this is a Rails list and not a Ruby list. but check it out, and I think it will more than answer your question. Matt On Thu, 2006-12-28 at 15:12 +0100, eddie wrote:> Hi, I''ve seen source like: params[:user] and params[''user''], or also > :action => ''new'' and :action => :new, is it also possible write > params["user"]? > So, which are the differences between '', " and : ? when use for example > : instead of others? > I''ve read that, for example, in a put(''name: #{user.name}'') the output > will be name: #{user.name} and with "" instead of '''' will be, for > example, name: John > is it right? > can anyone explain me these differences? > thanks :) >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
eddie wrote:> > thanks :) > I''ve taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby > I''m going immediately to study it... :)That will not take you very far. The first edition of "Programming Ruby" is available free, here: http://www.ruby-doc.org/ along with a lot of other documentation. Learn to use irb to try examples interactively. regards Justin --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Eddie, ''user'' != :user, but Rails uses HashWithIndifferentAccess instead of standard Hash i many places, so you can use params[:user] or params[''user''] See: http://api.rubyonrails.org/classes/HashWithIndifferentAccess.html http://redcorundum.blogspot.com/2006/07/symbolickeyhash.html http://devblog.famundo.com/articles/2006/05/13/beware-of-hashwithindifferentaccess-symbolize_keys Alain --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
I''d have to add that there''s a lot of new things Ruby''s learned to do between the two editions of the Pickaxe [the nickname readers have given to "Programming Ruby"]. Once you''ve made it through the first edition and feel like you and Ruby are a good fit you would do well to pick up a hard copy of the second edition. Everyone''s favorite method, Enumerable#inject, is a prime example of what you''re missing out on. RSL On 12/28/06, Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org> wrote:> > > eddie wrote: > > > > thanks :) > > I''ve taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby > > I''m going immediately to study it... :) > > That will not take you very far. The first edition of "Programming Ruby" > is available free, here: > > http://www.ruby-doc.org/ > > along with a lot of other documentation. > > Learn to use irb to try examples interactively. > > regards > > Justin > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---