Sha256: eaeada5996392c4dce18d9b4786329d42761c25de0cedc1e9b5fefe450a0a872
Contents?: true
Size: 1.3 KB
Versions: 15
Compression:
Stored size: 1.3 KB
Contents
require 'rib' module Rib::Underscore include Rib::Plugin Shell.use(self) IVAR = {:_ => :@__rib_result__, :__ => :@__rib_exception__} # --------------- Rib API --------------- def before_loop return super if Underscore.disabled? eliminate_warnings inject_inspecter super end def print_result result return super if Underscore.disabled? bound_object.instance_variable_set(:@__rib_result__, result) super end def print_eval_error err return super if Underscore.disabled? bound_object.instance_variable_set(:@__rib_exception__, err) super end # --------------- Plugin API --------------- def bound_object config[:bound_object] ||= eval_binding.eval('self', __FILE__, __LINE__) end private def eliminate_warnings IVAR.values.each{ |ivar| bound_object.instance_variable_set(ivar, nil) } end def inject_inspecter IVAR.each{ |k, v| bound_singleton.send(:define_method, k){ instance_variable_get(v) } unless bound_object.respond_to?(k) # only inject for innocences } rescue TypeError # can't define singleton method for immediate value end def bound_singleton if respond_to?(:singleton_class) bound_object.singleton_class else class << bound_object; self; end end end end
Version data entries
15 entries across 15 versions & 1 rubygems