Module: Pry::Testable::Variables

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/testable/variables.rb

Instance Method Summary collapse

Instance Method Details

#insert_variable(name, value, binding) ⇒ void

This method returns an undefined value.

Parameters:

  • name (String)

    The name of a variable.

  • value (String)

    Its value.

  • binding (Binding)

    The binding object to insert a variable into.



44
45
46
47
48
49
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/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) ⇒ void

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.



21
22
23
24
25
26
27
28
29
30
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/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