Class: Teacher::TopLevel
Instance Attribute Summary
Attributes inherited from Scope
#published_variables, #symbols
Instance Method Summary collapse
-
#initialize(*args) ⇒ TopLevel
constructor
A new instance of TopLevel.
Methods inherited from Scope
Constructor Details
#initialize(*args) ⇒ TopLevel
Returns a new instance of TopLevel.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/teacher/scope.rb', line 22 def initialize(*args) super self["min"] = Function.new(self) do |*arguments| arguments.min_by { |a| a.eval(self) } end self["sub"] = self["substitute"] = Function.new(self) do |target, origin| loop do target = target.eval(self) break if target.is_a?(Identifier) end @symbols[target.text_value] = origin.eval(self) end self["pub"] = self["publish"] = Function.new(self) do |identifier| @published_variables[identifier.text_value] = identifier.eval(self) end end |