add derivation possibility to class definition
This commit is contained in:
@ -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
|
||||
|
@ -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
|
Reference in New Issue
Block a user