Class: RVM::Interpreter::FunctionDefinition
- Inherits:
-
Object
- Object
- RVM::Interpreter::FunctionDefinition
- Defined in:
- lib/rvm/interpreter.rb
Overview
This is a function definition used to write in the function libary
Instance Method Summary collapse
- #execute(env) ⇒ Object
-
#initialize(name, body, override = true, pos = nil) ⇒ FunctionDefinition
constructor
Initializes a new function definition.
Constructor Details
#initialize(name, body, override = true, pos = nil) ⇒ FunctionDefinition
Initializes a new function definition
- name
-
is the name of the function to define, if it is not unique it will overwrite earlyer definitions (unless override is false)
- body
-
is the body of the cuntion. this will be executed when the defined function is called.
- override
-
when true (default) earlyer definitions are replaced when it is called a second time. When false a exception is thrown
256 257 258 259 260 261 |
# File 'lib/rvm/interpreter.rb', line 256 def initialize name, body, override = true, pos = nil @name = name @body = body @override = override @pos = pos end |
Instance Method Details
#execute(env) ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/rvm/interpreter.rb', line 263 def execute env if (not @override) and env.function(@name) raise "Function #{@name} already defined at #{@pos}!" end env.def_function(@name.execute(env),@body) nil end |