I’m saving to file Map class, which contains @width, @height, both
integers, and 2D array @fields of Field class. Field class contains @x,
@y, @terrain, @river, @forest, all are integers.
I’m saving using code:
File.open(filename, “w”) do |f|
f.write Marshal::dump(@map)
end
Next, in the same app, I’m trying to load map from file using:
File.open(filename, “rb”) do |f|
@map = Marshal::load(f)
end
I have got an ArgumentError in ‘load’: undefined class/module Field
which is raised when definition of class is not known.
But in my example I’m using require ‘map.rb’ and require ‘field.rb’ so
definitions of Map and Field are known.
I’ve tried to create new Field instance in a line before loading from
file, and it works with no error. So the Field class must be known.
What is a problem with this example? Why Field class is still undefined?
Thanks for help.