module BindingOfCallers::Reveal

Constants

InstanceVariableGet
InstanceVariableSet
InstanceVariables
Klass

Public Instance Methods

_binding() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 9
def _binding
  instance_variable_defined?(:@_binding) ? @_binding : self
end
call_symbol() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 51
def call_symbol
  @call_sym ||= singleton_method? ? '.' : '#'
end
env_type() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 67
def env_type
  _binding.frame_type
end
file() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 55
def file
  _binding.eval('__FILE__')
end
frame_env() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 63
def frame_env
  _binding.frame_description
end
inspect() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 13
def inspect
  "#<#{self.class}:#{object_id} #{file}:#{line} #{klass}#{call_symbol}#{frame_env}>"
end
iv(*args) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 17
def iv *args
  case args.count
  when 0
    all_iv
  when 1
    the_iv args[0]
  when 2
    set_iv(*args)
  end
end
klass() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 39
def klass
  return @klass if instance_variable_defined? :@klass
  determine_klass
  @klass
end
line() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 59
def line
  _binding.eval('__LINE__')
end
lv(*args) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 28
def lv *args
  case args.count
  when 0
    all_lv
  when 1
    the_lv args[0]
  when 2
    set_lv(*args)
  end
end
singleton_method?() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 45
def singleton_method?
  return @sm if instance_variable_defined? :@sm
  determine_klass
  @sm
end

Private Instance Methods

all_iv() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 87
    def all_iv
      determine_klass unless instance_variable_defined? :@from_object
      if @from_object
        _binding.eval <<-EOS
          instance_variables.each_with_object({}) do |iv_name, vars|
            vars[iv_name] = instance_variable_get(iv_name)
          end
        EOS
      else
        itself = binding_self
        _instance_variable_get = InstanceVariableGet.bind(itself)
        InstanceVariables.bind(itself).call.each_with_object({}) do |iv_name, vars|
          vars[iv_name] = _instance_variable_get.call iv_name
        end
      end
    end
all_lv() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 126
def all_lv
  _binding.send(:local_variables).each_with_object({}) do |lv_name, vars|
    vars[lv_name] = the_lv lv_name
  end
end
binding_self() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 122
def binding_self
  _binding.eval "instance_eval('self')"
end
determine_klass() click to toggle source
# File lib/binding_of_callers/reveal.rb, line 73
def determine_klass
  itself = binding_self
  @from_object = (Object === itself)
  binding_class = (@from_object ? itself.class : Klass.bind(itself).call)
  class_name = binding_class.name
  if class_name == 'Module' || class_name == 'Class'
    @sm = true
    @klass = itself
  else
    @sm = false
    @klass = binding_class
  end
end
set_iv(name, value) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 113
def set_iv name, value
  determine_klass unless instance_variable_defined? :@from_object
  if @from_object
    binding_self.instance_variable_set name, value
  else
    InstanceVariableSet.bind(binding_self).call name, value
  end
end
set_lv(name, value) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 136
def set_lv name, value
  _binding.local_variable_set name, value
end
the_iv(name) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 104
def the_iv name
  determine_klass unless instance_variable_defined? :@from_object
  if @from_object
    binding_self.instance_variable_get name
  else
    InstanceVariableGet.bind(binding_self).call name
  end
end
the_lv(name) click to toggle source
# File lib/binding_of_callers/reveal.rb, line 132
def the_lv name
  _binding.local_variable_get name
end