1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge pull request #2126 from pry/config-nil-on-unknown-option

config: return `nil` on unknown option instead of raising
This commit is contained in:
Kyrylo Silin 2020-04-12 15:17:03 +08:00 committed by GitHub
commit 9094b5f8d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View file

@ -5,6 +5,12 @@
* Fixed bug where on invalid input only the last syntax error is displayed * Fixed bug where on invalid input only the last syntax error is displayed
(instead of all of them) ([#2117](https://github.com/pry/pry/pull/2117)) (instead of all of them) ([#2117](https://github.com/pry/pry/pull/2117))
#### API changes
* `Pry::Config` returns `nil` on undefined option instead of raising
`NoMethodError` (usually invoked via `Pry.config.foo_option` calls)
([#2126](https://github.com/pry/pry/pull/2126))
### [v0.13.0][v0.13.0] (March 21, 2020) ### [v0.13.0][v0.13.0] (March 21, 2020)
#### Features #### Features

View file

@ -239,17 +239,17 @@ class Pry
@custom_attrs[attr.to_s].call @custom_attrs[attr.to_s].call
end end
def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper
def method_missing(method_name, *args, &_block)
name = method_name.to_s name = method_name.to_s
if name.end_with?('=') if name.end_with?('=')
self[name[0..-2]] = args.first self[name[0..-2]] = args.first
elsif @custom_attrs.key?(name) elsif @custom_attrs.key?(name)
self[name] self[name]
else
super
end end
end end
# rubocop:enable Style/MethodMissingSuper
def respond_to_missing?(method_name, include_all = false) def respond_to_missing?(method_name, include_all = false)
@custom_attrs.key?(method_name.to_s.tr('=', '')) || super @custom_attrs.key?(method_name.to_s.tr('=', '')) || super

View file

@ -150,8 +150,8 @@ RSpec.describe Pry::Config do
end end
context "when invoked method is not an option" do context "when invoked method is not an option" do
it "raises NoMethodError" do it "returns nil" do
expect { subject.foo }.to raise_error(NoMethodError) expect(subject.foo).to be_nil
end end
end end