mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Config#forget recursively removes a key from self and its default (#1899)
The following example should return 'Readline' after 'input' has been forgotten: # .pryrc Pry.config.input = RbReadline # Pry session pry(main)> _pry_.config.forget(:input) # This will unexpectedly return RbReadline instead of Pry's default, 'Readline' pry(main)> _pry_.config.input => RbReadline This commit fixes the above example to return 'Readline' after the 'input' option has been forgotten, allowing it to be restored to Pry's default.
This commit is contained in:
parent
dc8a191cae
commit
0d08ca3f8a
2 changed files with 8 additions and 7 deletions
|
@ -187,6 +187,7 @@ class Pry
|
||||||
def forget(key)
|
def forget(key)
|
||||||
key = key.to_s
|
key = key.to_s
|
||||||
__remove(key)
|
__remove(key)
|
||||||
|
default.forget(key) if default && default != last_default
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -155,13 +155,13 @@ RSpec.describe Pry::Config do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#forget" do
|
describe '#forget' do
|
||||||
it "forgets a local key" do
|
it 'restores a key to its default value' do
|
||||||
local = described_class.new described_class.from_hash(foo: 1)
|
last_default = described_class.from_hash(a: 'c')
|
||||||
local.foo = 2
|
middle_default = described_class.from_hash({a: 'b'}, last_default)
|
||||||
expect(local.foo).to eq 2
|
c = described_class.from_hash({a: 'a'}, middle_default)
|
||||||
local.forget(:foo)
|
c.forget(:a)
|
||||||
expect(local.foo).to eq(1)
|
expect(c.a).to eq('c')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue