class Klam::Environment
Public Class Methods
def_method(name, proc)
click to toggle source
Define method is private, so open it up
# File lib/klam/environment.rb, line 61 def def_method(name, proc) define_method(name, proc) end
new()
click to toggle source
# File lib/klam/environment.rb, line 16 def initialize # The global assignments namespace. Errors are thrown here in the # missing element handler rather than in the value primitive in order # to facilitate inlining later. @assignments = ::Hash.new do |_, name| ::Kernel.raise ::Klam::Error, "The variable #{name} is unbound." end @arities = ::Hash.new { |h, k| h[k] = __arity(k) } @curried_methods = ::Hash.new { |h, k| h[k] = __method(k).to_proc.curry } # Grab a handle to this object's eigenclass for use later when the # compiled code needs to reference it. It is used, e.g., when renaming # methods. @eigenclass = class << self; self; end @compiler = ::Klam::Compiler.new(self) # The open primitive depends on having *home-directory* assigned. set(:"*home-directory*", ::Dir.pwd) set(:"*dump-kl*", false) set(:"*dump-rb*", false) set(:"*include-backtrace-in-error-string*", false) end
rename_method(old_name, new_name)
click to toggle source
# File lib/klam/environment.rb, line 65 def rename_method(old_name, new_name) alias_method(new_name, old_name) remove_method(old_name) end
Public Instance Methods
__apply(rator, *rands)
click to toggle source
# File lib/klam/environment.rb, line 41 def __apply(rator, *rands) if rator.kind_of?(::Symbol) @curried_methods[rator].call(*rands) else rator.call(*rands) end end
__arity(sym)
click to toggle source
# File lib/klam/environment.rb, line 53 def __arity(sym) @eigenclass.instance_method(sym).arity rescue ::NameError -1 end
__method(sym)
click to toggle source
# File lib/klam/environment.rb, line 49 def __method(sym) @eigenclass.instance_method(sym).bind(self) end