关于# Signs 的Ruby 问题 [英] Ruby question about # Signs
本文介绍了关于# Signs 的Ruby 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如这里所示:http://railstutorial.org/chapters/rails-flavored-ruby#top 用于文件:
As seen here: http://railstutorial.org/chapters/rails-flavored-ruby#top for the file:
app/helpers/application_helper.rb:
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
为什么在 base_title 和 Title 之前有井号?他们在做什么?
Why are there pound signs before base_title and before Title? What are they doing?
推荐答案
这叫做字符串插值.base_title 是一个变量,#{} 字符表示应该替换它的值来代替该标记.
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.
这篇关于关于# Signs 的Ruby 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文