我正在调试一个程序,它没有在加载的文件中执行新的puts。主文件正在运行,并执行对该文件的更改。所以我怀疑任何改变都会被载入。
我做错什么了?
第一个文件工作正常。这是第二个文件..。在运行时提示符不会更改的newmods.rb文件,并且没有使用任何新的“puts”语句。我使用load而不是require_relative。该文件不使用require_relative编译。
档案1
#!/usr/bin/env ruby
load "/Users/abcde/Ruby/learning/shorterZork/monsters.rb"
load "/Users/abcde/Ruby/learning/shorterZork/room.rb"
load "/Users/abcde/Ruby/learning/shorterZork/avatar.rb"
load "/Users/abcde/Ruby/learning/shorterZork/newmods.rb"
load "/Users/abcde/Ruby/learning/shorterZork/items.rb"
def main()
game_loop(avatar)
end
def game_loop(avatar)
puts "You are in the: #{@room_name}"
puts "#{avatar.name} has #{avatar.life}!"
health_bar(avatar)
# Check for avatar's life.
#avatar_life(avatar)
#puts @room_monsters.to_s
monster = @room_monsters
test_encounter(avatar, monster)
# need to put the meat of the game here.
# puts "I need something here."
#puts "--------------------------------------------This is the main loop."
prompt; action = gets.chomp
if action.downcase == "help"
help()
..etc...etc.
end
main()文件2 newmods.rb
# This includes any modules that might be nice to use.
load "/Users/abcde/Ruby/learning/shorterZork/monsters.rb"
load "/Users/abcde/Ruby/learning/shorterZork/room.rb"
load "/Users/abcde/Ruby/learning/shorterZork/avatar.rb"
load "/Users/abcde/Ruby/learning/shorterZork/items.rb"
#require 'items'
#require 'monsters'
#require 'avatar'
#require 'room'
#require 'shortZork'
def prompt()
print ">> "
end发布于 2015-08-21 16:54:51
Joy。就在你伸出援手的时候,答案拍打着你的脸。
ruby加载是从与当前预期路径不同的路径加载文件。用户名不一样所以..。
发布于 2015-08-20 01:30:34
根据我的经验,在这种情况下常见的错误是
https://stackoverflow.com/questions/32107915
复制相似问题