I am a newbie. Looking at some old text vs new. I see some changes: New: <%= yield(:title) %> Old: <%= @title %> New: "#{base_title} | Home" Old: @base_title + "| Home" Can you tell me when they got changed? Are the new syntax now the preferred way? Are they more elegant? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/dsR8sPd7BgEJ. For more options, visit https://groups.google.com/groups/opt_out.
On Sep 9, 2012, at 12:10 PM, rails2012 wrote:> I am a newbie. Looking at some old text vs new. I see some changes: > > New: <%= yield(:title) %> > Old: <%= @title %> >Not sure about this one.> New: "#{base_title} | Home" > Old: @base_title + "| Home"The new way creates one fewer String object, and that can only be good for performance and memory usage. Walter> > Can you tell me when they got changed? Are the new syntax now the preferred way? Are they more elegant? > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/dsR8sPd7BgEJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
> New: <%= yield(:title) %> > Old: <%= @title %>@title is set in a controller, and to separate views from what goes on in a controller, you shouldn''t set a title of an html page in a controller. The method yield(:title) looks for the value of a title variable in the view, which can be set like this: <% provide(:title, "Home") %>> New: "#{base_title} | Home" > Old: @base_title + "| Home"Those statements do the exact same thing in ruby. The first example injects a second string into the first string. The second example joins two strings together--producing a third string. So the second example is a tiny bit more efficient. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Do you mean "#{base_title} | Home" is more efficient because it doesn''t create a new String object? (You said second one... I am not sure if I got that right.) (I wonder why I don''t get email notifications when replies are sent... I am pretty sure I clicked "Email updates to me"...)> > New: "#{base_title} | Home" > > Old: @base_title + "| Home" > > Those statements do the exact same thing in ruby. The first example > injects a second string into the first string. The second example joins > two strings together--producing a third string. So the second example is > a tiny bit more efficient. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kRvPL7Ht7PEJ. For more options, visit https://groups.google.com/groups/opt_out.
Well, if you are getting posts on the mailing list, then I guess you don''t get the edits, which are allowed for 15 minutes. I corrected that error in my post--right after I posted. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Derek Lin wrote in post #1075271:> Do you mean "#{base_title} | Home" is more efficient because it doesn''t > create a new String object? >It certainly does create a new String object--that''s what the quotes do; they tell Ruby, "Please create a new String object for me. The difference is that the following: base_title + "| Home" ...creates two more String objects: "| Home" and another created by +. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.