-2
从_why的书中学习Ruby,我尝试重新创建他的代码,但它不起作用。require_relative不拉动变量?
我有一个world.rb文件;
puts "Hello World"
Put_the_kabosh_on = "Put the kabosh on"
code_words = {
starmonkeys: "Phil and Pete, thouse prickly chancellors of the New Reich",
catapult: "Chunky go-go",
firebomb: "Heat-Assisted Living",
Nigeria: "Ny and Jerry's Dry Cleaning (with Donuts)",
Put_the_kabosh_on: "Put the cable box on"
}
而在我的其他文件,pluto.rb;
require_relative "world"
puts "Hello Pluto"
puts code_words[:starmonkeys]
puts code_words[:catapult]
puts code_words[:firebomb]
puts code_words[:Nigeria]
puts code_words[:Put_the_kabosh_on]
我知道我的require_relative
的作品,因为如果我不散列部(只是把"Hello World"
)运行pluto.rb,您好世界获取打印!
如果你expectecting的code_words局部变量pluto.rb存在,那么它不会。这是要求(_relative)工作的方式 –
您的问题是什么? – sawa
在一个Rails应用程序中,你应该把它们放在一个YAML文件中。看看http://guides.rubyonrails.org/i18n.html – Stefan