Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: return nil on unknown option instead of raising #2126

Merged
merged 1 commit into from Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/pry/config.rb
Expand Up @@ -239,17 +239,17 @@ def [](attr)
@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
Expand Down
4 changes: 2 additions & 2 deletions spec/config_spec.rb
Expand Up @@ -150,8 +150,8 @@
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

Expand Down