0
루비를 배우기 위해 '왜 루비에 대한 신랄한 가이드'를 따르고 있으며 튜토리얼에서 '필요'메소드 (?)를 처음 소개 할 때 몇 가지 문제가 있습니다. 그때 또 다른 루비가 Ruby에서 간단한 'require'문제가 발생했습니다.
code_words = {
'starmonkeys' => 'Phil and Pete, those prickly chancellors of the New Reich',
'catapult' => 'chucky go-go', 'firebomb' => 'Heat-Assisted Living',
'Nigeria' => "Ny and Jerry's Dry Cleaning (with Donuts)",
'Put the kabosh on' => 'Put the cable box on'
}
가 'files.rb'라는 scipt :
는 기본적으로 내가 포함 'wordlist.rb'라는 파일을
require 'wordlist'
#Get evil idea and swap in code words
print "Enter your new idea: "
idea = gets
#real will have the key and code will have the value
#Method followed by ! (like gsub!) are known as destructive methods
code_words.each do |real, code|
safe_idea = idea.gsub!(real,code)
end
#Save the jibberish to a new file
print "File encoded. Please enter a name for this idea: "
idea_name = gets.strip
File::open("idea-" + idea_name + ".txt", "w") do |f|
f
내가 실행하려고 루비 스크립트 내가 얻을 :
files.rb:9: undefined local variable or method `code_words' for main:Object (NameError)
어떻게 'require'를 참조 단어 목록을 제대로 작동시키는 지 알기를 원하십니까?