8000 fix: add guard clause to check if matches is nil by ratheeshaditya · Pull Request #917 · countries/countries · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: add guard clause to check if matches is nil #917

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

Merged
merged 2 commits into from
Jun 30, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/countries/country/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ def method_missing(method_name, *arguments)
# :reek:BooleanParameter
def respond_to_missing?(method_name, include_private = false)
matches = method_name.to_s.match(FIND_BY_REGEX)
return super unless matches && matches[3]

method = matches[3]
if matches && method
instance_methods.include?(method.to_sym)
else
super
end

instance_methods.include?(method.to_sym)
end

protected
Expand Down
4 changes: 4 additions & 0 deletions spec/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

let(:country) { ISO3166::Country.search('US') }

it 'handles respond_to_missing values' do
expect(described_class.respond_to?(:arr)).not_to be_nil
end

it 'allows to create a country object from a symbol representation of the alpha2 code' do
country = described_class.new(:us)
expect(country.data).not_to be_nil
Expand Down
Loading
0