Sha256: 67b203bbdadb60de76f66c177f508cc1bac4b3a440b9e74fa5f880624ce0db36
Contents?: true
Size: 1.05 KB
Versions: 30
Compression:
Stored size: 1.05 KB
Contents
class Bindless def initialize(bindings = []) @bindings = bindings end def method_missing(m, *args) @bindings.reverse_each do |bind| begin method = eval("method(%s)" % m.inspect, bind) rescue NameError else return method.call(*args) end begin value = eval(m.to_s, bind) return value rescue NameError end end raise NoMethodError, "No such variable or method: %s" % m end def pop_binding @bindings.pop end def push_binding(bind) @bindings.push bind end def push_instance(obj) @bindings.push obj.instance_eval { binding } end def push_hash(vars) push_instance Struct.new(*vars.keys).new(*vars.values) end def get_binding instance_eval { binding } end def run_proc(p, *args) instance_exec(*args, &p) end def push_method(name, p, obj=nil) x = Object.new singleton = class << x; self; end singleton.send(:define_method, name, lambda { |*args| obj.instance_exec(*args, &p) }) push_instance x end end
Version data entries
30 entries across 30 versions & 1 rubygems