0

I have a module like this

module urlfetch
  class fetch

    def initialize(url)
      @url = url
      analyze!
    end

   #extra methods goes here

  end
end

I tried like this

response = urlfetch::fetch("http://google.com")
puts response

But i'm getting error like undefined method fetch

2 Answers 2

4

classes and modules in ruby are defined by uppercase names so

module Urlfetch
  class Fetch

    def initialize(url)
      @url = url
      analyze!
    end

   #extra methods goes here

  end
end

then you initialize a class via the new method

response = Urlfetch::Fetch.new("http://google.com")
puts response
Sign up to request clarification or add additional context in comments.

Comments

2

First off, modules and classes should be capitalised, as constants. Secondly, you need new to construct an object.

URLFetch::Fetch.new("http://google.com")

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.