diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2020-04-12 15:17:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-12 15:17:03 +0800 |
commit | 9094b5f8d47e61c1cf64ac07847d46b09e7ef932 (patch) | |
tree | 9e526ce4e14379547b39633ac6369f62ad5b62b7 | |
parent | f0328a4dfa88a98d344086526d8e5a778b0452fd (diff) | |
parent | 5dd061c3406aa84e5cafd489a5c77e550b00d122 (diff) | |
download | pry-9094b5f8d47e61c1cf64ac07847d46b09e7ef932.tar.gz |
Merge pull request #2126 from pry/config-nil-on-unknown-option
config: return `nil` on unknown option instead of raising
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | lib/pry/config.rb | 6 | ||||
-rw-r--r-- | spec/config_spec.rb | 4 |
3 files changed, 11 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 85796fda..180b7737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ * 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)) +#### 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) #### Features diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 6c377a48..0e54bf69 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -239,17 +239,17 @@ class Pry @custom_attrs[attr.to_s].call end - def method_missing(method_name, *args, &block) + # rubocop:disable Style/MethodMissingSuper + def method_missing(method_name, *args, &_block) name = method_name.to_s if name.end_with?('=') self[name[0..-2]] = args.first elsif @custom_attrs.key?(name) self[name] - else - super end end + # rubocop:enable Style/MethodMissingSuper def respond_to_missing?(method_name, include_all = false) @custom_attrs.key?(method_name.to_s.tr('=', '')) || super diff --git a/spec/config_spec.rb b/spec/config_spec.rb index db91f7cb..f1cf5ea6 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -150,8 +150,8 @@ RSpec.describe Pry::Config do end context "when invoked method is not an option" do - it "raises NoMethodError" do - expect { subject.foo }.to raise_error(NoMethodError) + it "returns nil" do + expect(subject.foo).to be_nil end end |