I have this class in file "ghost.rb":
class Ghost attr_accessor :fragment def initialize(number_of_players) @fragment = '' end end I'm trying to access @fragment from another file in the same directory. Below is "aiplayer.rb" in the same directory.
require "./ghost" class Aiplayer attr_reader :aiplayer def initialize @aiplayer = Player.new('AI Player') end def fragment_printer Ghost.fragment end end When I initialize an instance of Aiplayer and call the fragment_printer method on it, I get the following error:
NoMethodError: undefined method `fragment' for Ghost:Class from aiplayer.rb:17:in `fragment_printer' I have the attr_accessor there, and so I'm not sure why I cannot reach the fragment variable from outside of the Ghost class. I'm having issues accessing class instance variables from outside of the class. Can anyone give me an explanation on this?
Ghost?class Ghost; class << self; attr_accessor :fragment; end; end;