Class: ClassNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/toylang/ast/nodes.rb,
lib/toylang/interpreter/evaluation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



43
44
45
# File 'lib/toylang/ast/nodes.rb', line 43

def body
  @body
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



43
44
45
# File 'lib/toylang/ast/nodes.rb', line 43

def name
  @name
end

#superclassObject

Returns the value of attribute superclass

Returns:

  • (Object)

    the current value of superclass



43
44
45
# File 'lib/toylang/ast/nodes.rb', line 43

def superclass
  @superclass
end

Instance Method Details

#eval(context) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/toylang/interpreter/evaluation.rb', line 100

def eval(context)
  toylang_class = context[name]

  unless toylang_class
    toylang_class = ToyLangClass.new(Runtime[superclass || 'Object'])
    context[name] = toylang_class
  end

  class_context = Context.new(toylang_class, toylang_class)
  body.eval(class_context)

  toylang_class
end