As seen here: http://railstutorial.org/chapters/rails-flavored-ruby#top for 开发者_开发问答the file:
app/helpers/application_helper.rb:
module ApplicationHelper
# Return a title on a per-page basis.
def title
base_title = "Ruby on Rails Tutorial Sample App"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
end
Why are there pound signs before base_title and before Title? What are they doing?
It's called string interpolation. base_title is a variable, and the #{} characters denote that its value should be substituted in place of that marker.
It's string interpolation. Eg:
name = "nobosh"
puts "Hello, #{name}."
Prints
Hello, nobosh.
精彩评论