Class: Halunke::FunctionNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/halunke/nodes.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



76
77
78
# File 'lib/halunke/nodes.rb', line 76

def body
  @body
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



76
77
78
# File 'lib/halunke/nodes.rb', line 76

def params
  @params
end

#teObject

Returns the value of attribute te

Returns:

  • (Object)

    the current value of te



76
77
78
# File 'lib/halunke/nodes.rb', line 76

def te
  @te
end

#tsObject

Returns the value of attribute ts

Returns:

  • (Object)

    the current value of ts



76
77
78
# File 'lib/halunke/nodes.rb', line 76

def ts
  @ts
end

Instance Method Details

#==(other) ⇒ Object



86
87
88
89
90
# File 'lib/halunke/nodes.rb', line 86

def ==(other)
  other.is_a?(FunctionNode) &&
    params == other.params &&
    body == other.body
end

#eval(context) ⇒ Object

Raises:



77
78
79
80
81
82
83
84
# File 'lib/halunke/nodes.rb', line 77

def eval(context)
  raise HEmptyFunction.new("This function would not return anything, in Halunke every function needs to return something.", source_code_position) if body.empty?
  signature = params.nodes.map(&:node).map(&:value)

  context["Function"].new(signature, lambda { |call_context|
    body.eval(call_context)
  })
end

#source_code_positionObject



92
93
94
# File 'lib/halunke/nodes.rb', line 92

def source_code_position
  SourceCodePosition.new(ts, te)
end