我正在调试程序,并且它没有在加载的文件中执行新的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
答案 0 :(得分:0)
根据我的经验,在这种情况下常见的错误是
答案 1 :(得分:0)
喜悦。就在你伸手去寻求帮助的时候,答案就会让你失意。
ruby加载是从与当前预期路径不同的路径加载文件。用户名不同,所以......