add derivation possibility to class definition

This commit is contained in:
Torsten Ruger
2014-06-19 18:16:54 +02:00
parent 06d4ab2fe5
commit 969f2529a2
7 changed files with 48 additions and 21 deletions

View File

@ -24,7 +24,7 @@ module Ast
@name = name.to_sym
end
def inspect
"#{self.class.name}.new(#{name})"
"#{self.class.name}.new(#{name.inspect})"
end
def to_s
name.to_s

View File

@ -20,5 +20,22 @@ module Ast
class ClassExpression < ModuleExpression
def initialize name , derived , expressions
super(name , expressions)
@derived_from = derived
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," +
@derived_from.inspect + ", " + @expressions.inspect + " )"
end
def derived_from
@derived_from ? @derived_from : :Object
end
def to_s
s = "class #{name} < #{derived_from}\n #{expressions}\nend\n"
end
def attributes
[:name , :derived_from , :expressions]
end
end
end