【发布时间】:2011-07-06 03:36:25
【问题描述】:
我在 file2.rb 下保存了以下哈希
codewords = {'starmonkeys' => 'Five edged primates.'}
*你们中的一些人可能会从《辛酸指南》中认出这一点!
file1.rb下还有以下内容:
if __FILE__ == $0
require File.expand_path('C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\why the lucky stiff made me do this\file2.rb', __FILE__)
print "Enter your secret sentence."
idea = gets
codewords.each do | real , code|
idea.gsub!( real , code )
end
#Saving to a new file
print "File encoded. Print a file name for this idea"
idea_name = gets.strip
File::open( "idea-"+idea_name+".txt","w" ) do |f|
f<<idea
end
end
我提出了一个 NameError: file.rb:7:in <main>': undefined local variable or methodcodewords' for main:Object (NameError)
我做错了什么导致这个问题?
【问题讨论】: