Sha256: 6840528b98931cbe15a8712c3ac7f31ba248a99ebccc59ed916feb36a39b2bd4

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

module Pry::Testable::Variables
  #
  # @example
  #   temporary_constants(:Foo, :Bar) do
  #     Foo = Class.new(RuntimeError)
  #     Bar = Class.new(RuntimeError)
  #   end
  #   Foo # => NameError
  #   Bar # => NameError
  #
  # @param [Array<Symbol>] *names
  #   An array of constant names that be defined by a block,
  #   and removed by this method afterwards.
  #
  # @return [void]
  #
  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

  #
  # @param [String] name
  #   The name of a variable.
  #
  # @param [String] value
  #   Its value.
  #
  # @param [Binding] b
  #   The binding object to insert a variable into.
  #
  # @return [void]
  #
  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
end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/testable/variables.rb
pry-0.11.3 lib/pry/testable/variables.rb
pry-0.11.3-java lib/pry/testable/variables.rb