Class: AmberVM::Classes::Block
- Defined in:
- lib/amber/classes/block.rb
Defined Under Namespace
Classes: Variable_container
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
- #call(params, env, pos = nil) ⇒ Object
- #execargs ⇒ Object
- #execute(env) ⇒ Object
-
#initialize(code) ⇒ Block
constructor
A new instance of Block.
- #optimize(variables = {}) ⇒ Object
Methods inherited from Class
#data_type, #functions, #is_true?, #method_missing, #obj_send, #variables
Methods included from Plugin
#helper, #included, #plugin_host, #plugin_id, #register_for
Constructor Details
#initialize(code) ⇒ Block
Returns a new instance of Block.
6 7 8 9 10 |
# File 'lib/amber/classes/block.rb', line 6 def initialize code super() @type = :any @code = code end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AmberVM::Classes::Class
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/amber/classes/block.rb', line 4 def code @code end |
Instance Method Details
#call(params, env, pos = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/amber/classes/block.rb', line 43 def call params, env, pos = nil AmberVM::debug "Calling Block at #{pos}...(evn: #{env.pretty_inspect}, params: #{params})" if $DEBUG env = AmberVM::Interpreter::Environment.new({:params => params||[]}, env) return (catch :return do @code.execute(env) end).val end |
#execargs ⇒ Object
15 16 17 |
# File 'lib/amber/classes/block.rb', line 15 def execargs true end |
#execute(env) ⇒ Object
12 13 |
# File 'lib/amber/classes/block.rb', line 12 def execute env end |
#optimize(variables = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/amber/classes/block.rb', line 34 def optimize variables = {} #old_keys = Set.new(variables.keys) code = @code.optimize variables #(Set.new(variables.keys) - old_keys).each do |key| # variables.delete(key) #end Block.new(code) end |