Class: DefNode

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



41
42
43
# File 'lib/toylang/ast/nodes.rb', line 41

def body
  @body
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



41
42
43
# File 'lib/toylang/ast/nodes.rb', line 41

def name
  @name
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



41
42
43
# File 'lib/toylang/ast/nodes.rb', line 41

def params
  @params
end

Instance Method Details

#eval(context) ⇒ Object



93
94
95
96
# File 'lib/toylang/interpreter/evaluation.rb', line 93

def eval(context)
  method = ToyLangMethod.new(params, body)
  context.current_class.runtime_methods[name] = method
end