6

I have the following code to get google.com

class Geocoder
    def self.locate()

        uri="http://www.google.com/"



        puts Net::HTTP.get(uri)

end

but i faced with the erorr:

undefined method `hostname' for "'http://www.google.com/":String (NoMethodError)

I have already seen this, and my ruby version is: ruby 2.2.1

1
  • 3
    You also have a single quote inside your double-quoted string, there. Commented Nov 20, 2015 at 9:23

1 Answer 1

19

You're missing parsing the string into a URI... Here is what it should look like:

class Geocoder
  def self.locate(address)
    escaped_address = URI.escape(address) 
    uri = URI.parse(escaped_address)
    puts Net::HTTP.get(uri)
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.