Skip to content

Commit

Permalink
config: return nil on unknown option instead of raising
Browse files Browse the repository at this point in the history
Returning `nil` on unknown option was default behaviour for Pry v0.12.x. In
e5556a2 I changed that but I am not sure if it
was intentional. This breaks plugins such as
pry-theme (kyrylo/pry-theme#59).

Returning `nil` makes more sense, because we can write code like this:

```
Pry.config.foo ||= 123
```

...whereas as of now this is no longer possible and you would need to use
`respond_to?` to achieve the same effect.
  • Loading branch information
kyrylo committed Apr 12, 2020
1 parent f0328a4 commit fb60852
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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)
([#1877](https://github.com/pry/pry/pull/1877))

### [v0.13.0][v0.13.0] (March 21, 2020)

#### Features
Expand Down
3 changes: 2 additions & 1 deletion lib/pry/config.rb
Expand Up @@ -247,7 +247,8 @@ def method_missing(method_name, *args, &block)
elsif @custom_attrs.key?(name)
self[name]
else
super
nil
# super
end
end

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

0 comments on commit fb60852

Please sign in to comment.