I have a json file. I am using it to store information, and as such it is constantly going to be both read and written.
I am completely new to ruby and oop in general, so I am sure I am going about this in a crazy way.
class Load
def initialize(save_name)
puts "loading " + save_name
@data = JSON.parse(IO.read( $user_library + save_name ))
@subject = @data["subject"]
@id = @data["id"]
@save_name = @data["save_name"]
@listA = @data["listA"] # is an array containing dictionaries
@listB = @data["listB"] # is an array containing dictionaries
end
attr_reader :data, :subject, :id, :save_name, :listA, :listB
end
example = Load.new("test.json")
puts example.id
=> 937489327389749
So I can now easily read the json file, but how could I write back to the file - refering to example? say I wanted to change the id example.id.change(7129371289)
... or add dictionaries to lists A and B... Is this possible?