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,8 +10,24 @@
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