Module: Pry::Testable::Variables

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

Instance Method Summary collapse

Instance Method Details

#insert_variable(name, value, b)

This method returns an undefined value.

Parameters:

  • name (String)

    The name of a variable.

  • value (String)

    Its value.

  • b (Binding)

    The binding object to insert a variable into.



40
41
42
43
44
45
# File 'lib/pry/testable/variables.rb', line 40

def insert_variable(name, value, b)
  Pry.current[:pry_local] = value
  b.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

Parameters:

  • names (Array<Symbol>)

    An array of constant names that be defined by a block, and removed by this method afterwards.



17
18
19
20
21
22
23
24
25
26
# File 'lib/pry/testable/variables.rb', line 17

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