Class: SelfML::AST::Node
- Inherits:
-
Object
- Object
- SelfML::AST::Node
- Defined in:
- lib/selfml/ast.rb
Instance Attribute Summary (collapse)
-
- (Object) head
Returns the value of attribute head.
-
- (Object) tail
Returns the value of attribute tail.
Instance Method Summary (collapse)
- - (Object) <=>(rhs)
-
- (Node) initialize(head, tail = [])
constructor
A new instance of Node.
- - (Object) serialize(level = 1) (also: #to_s)
Constructor Details
- (Node) initialize(head, tail = [])
A new instance of Node
17 18 19 |
# File 'lib/selfml/ast.rb', line 17 def initialize( head , tail = [] ) @head , @tail = head , tail end |
Instance Attribute Details
- (Object) head
Returns the value of attribute head
15 16 17 |
# File 'lib/selfml/ast.rb', line 15 def head @head end |
- (Object) tail
Returns the value of attribute tail
15 16 17 |
# File 'lib/selfml/ast.rb', line 15 def tail @tail end |
Instance Method Details
- (Object) <=>(rhs)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/selfml/ast.rb', line 38 def <=> rhs case rhs when Node 0 when StringNode 1 else -1 end end |
- (Object) serialize(level = 1) Also known as: to_s
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/selfml/ast.rb', line 21 def serialize level=1 tail = @tail.sort.map do |t| case t when Node "\n" + " "*level*4 + "#{t.serialize level+1}" when StringNode " #{t.serialize}" else nil end end "(#{head.serialize}#{tail})" end |