@title is a type of variable that 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. yield(:title) looks for the value of a title
variable in the view, which can be set like this:
Those statements do the exact same thing in ruby. The first example
injects an existing string, base_title, into the creation process of
another string. The second example joins two strings
together–producing a third string. So the first example is a tiny
bit more efficient.
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.
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”…)
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 +.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.