-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]
私は(ちょうど"Hello World"
を置く)ハッシュ部分なしでpluto.rbを実行した場合、Hello Worldのが印刷されますので!私は、私のrequire_relative
作品を知っています
をあなたはpluto.rbに存在することがcode_wordsローカル変数をexpectectingしている場合、その後、あなたがそれらを名前空間にモジュールに入れた場合、それは良いだろうそれはしません。これはrequire(_relative)が動作する方法です –
あなたの質問は何ですか? – sawa
Railsアプリケーションでは、これらをYAMLファイルに配置する必要があります。 http://guides.rubyonrails.org/i18n.htmlをご覧ください – Stefan