start on to_json and json_create

This commit is contained in:
Torsten Ruger 2015-07-11 21:59:36 +03:00
parent 99493865c1
commit 657d6319ad

View File

@ -10,17 +10,33 @@
module Ast
class Expression
def attributes
[]
raise "abstract called for #{self}"
end
def to_json(*a)
data = {}
attributes.each do |name|
data[name] = instance_variable_get(name)
end
puts data
{
"json_class" => self.class.name,
"data" => data
}.to_json(*a)
end
def self.json_create(o)
new(*o["data"].values)
end
def inspect
self.class.name + ".new()"
end
def == other
return false unless other.class == self.class
return false unless other.class == self.class
attributes.each do |a|
left = send(a)
right = other.send(a)
return false unless left.class == right.class
return false unless left.class == right.class
return false unless left == right
end
return true