Class: Rubic::Environment
- Inherits:
-
Object
- Object
- Rubic::Environment
- Defined in:
- lib/rubic/environment.rb
Instance Method Summary collapse
- #bind(params, args) ⇒ Object
- #defvar(name, value) ⇒ Object (also: #[]=)
-
#initialize(outer = nil) ⇒ Environment
constructor
A new instance of Environment.
- #refvar(name) ⇒ Object (also: #[])
Constructor Details
#initialize(outer = nil) ⇒ Environment
Returns a new instance of Environment.
5 6 7 8 |
# File 'lib/rubic/environment.rb', line 5 def initialize(outer=nil) @outer = outer @table = {} end |
Instance Method Details
#bind(params, args) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rubic/environment.rb', line 24 def bind(params, args) if params.size != args.size raise RubicRuntimeError, "wrong number of arguments (#{args.size} for #{params.size})" end params.each.with_index do |name, i| @table[name] = args[i] end end |
#defvar(name, value) ⇒ Object Also known as: []=
10 11 12 |
# File 'lib/rubic/environment.rb', line 10 def defvar(name, value) @table[name] = value end |
#refvar(name) ⇒ Object Also known as: []
14 15 16 17 18 19 20 21 22 |
# File 'lib/rubic/environment.rb', line 14 def refvar(name) if @table.key? name @table[name] elsif @outer @outer.refvar(name) else raise RubicRuntimeError, "undefined variable `#{name}'" end end |