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

existing constant name shadowing a lookup class name results in NoMethodError #1588

Conversation

avram-twitch
Copy link

Related issue here: #1568

It was marked as close and resolved, but I'm still seeing the same problem. I was able to recreate the bug on ruby 2.6.3 and geocoder version 1.8.0 with the following

require 'geocoder'

module Google
end

Geocoder.configure(:api_key => "YOUR-KEY", :lookup => :google)
Geocoder.search("Something")

Results in

Traceback (most recent call last):
        6: from test.rb:7:in `<main>'
        5: from /Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder.rb:22:in `search'
        4: from /Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder/query.rb:11:in `execute'
        3: from /Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder/query.rb:40:in `lookup'
        2: from /Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder/lookup.rb:108:in `get'
        1: from /Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder/lookup.rb:121:in `spawn'
/Users/avramtwitchell/.rvm/gems/ruby-2.6.3/gems/geocoder-1.8.0/lib/geocoder/lookup.rb:146:in `instantiate_lookup': undefined method `new' for Google:Module (NoMethodError)

I added the inherit=false flag to the const_get call, which prevents looking up constants higher up in the module namespace. I also added a test that fails with the code as it was. I'm unfamiliar with using the test-unit gem for testing, so feel free to make suggestions!

@avram-twitch avram-twitch changed the title Fixes errors occurring when existing constant name shadows a lookup c… existing constant name shadowing a lookup class name results in NoMethodError Aug 1, 2022
@avram-twitch avram-twitch force-pushed the fixes-shadowed-lookup-class-name-bug branch from f410d5d to 145991b Compare August 1, 2022 19:38
@avanrielly
Copy link

@alexreisner Is there any chance of this getting merged? We just updated to 1.8.0 and we are getting this same error.

@alexreisner
Copy link
Owner

Sorry, this somehow slipped through the cracks. Reviewing now, will merge shortly. Will also release 1.8.1 soon.

@alexreisner alexreisner merged commit 9f7d485 into alexreisner:master Sep 23, 2022
@avanrielly
Copy link

Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants