我正在尝试使用下面的 ruby 类学习课程,我只是不明白输出语句的结果是如何通过调用 player 函数后跟新变量的“John Smith”?
有没有更简单的方法呢?编码器以我感到困惑的方式做到了最后,你能告诉我如何调试 Ruby 类或 TextMate 上的任何 ruby 代码吗?我的意思是调试,就像在 Visual C++ 中调试一样,向我展示了第一行被调用和执行的内容,然后跳转到下一行等……看看它是如何工作的?
class Dungun
attr_accessor :player
def initialize(player_name)
@player = Player.new(player_name)
@rooms = []
end
class Player
attr_accessor :name, :location
def initialize(player_name)
@name = player_name
end
end
class Room
attr_accessor :reference, :name, :description, :connection
def initialize(reference,name,description,connection)
@reference = reference
@name = name
@description = description
@connection = connection
end
end
end
my_dungun = Dungun.new("John Smith")
puts my_dungun.player.name