Module: Pry::Testable::Variables

Defined in:
lib/pry/testable/variables.rb

Instance Method Summary collapse

Instance Method Details

#insert_variable(name, value, binding)


44
45
46
47
48
49
# File 'lib/pry/testable/variables.rb', line 44

def insert_variable(name, value, binding)
  Pry.current[:pry_local] = value
  binding.eval("#{name} = ::Pry.current[:pry_local]")
ensure
  Pry.current[:pry_local] = nil
end

#temporary_constants(*names)

This method returns an undefined value.

Examples:

temporary_constants(:Foo, :Bar) do
  Foo = Class.new(RuntimeError)
  Bar = Class.new(RuntimeError)
end
Foo # => NameError
Bar # => NameError

21
22
23
24
25
26
27
28
29
30
# File 'lib/pry/testable/variables.rb', line 21

def temporary_constants(*names)
  names.each do |name|
    Object.remove_const name if Object.const_defined?(name)
  end
  yield
ensure
  names.each do |name|
    Object.remove_const name if Object.const_defined?(name)
  end
end