Scope Missunderstanding

i got a module x and then a class z and inside this class i do a
Net::HTTP call and it looks for it inside module x … and i am
clueless…

i get uninitialized constant ModuleX::Net::HTTP

i am new to ruby… and i just dont know how the scope works…
or what i am doing wrong

i took a look at the soap module
and it dosent look like it does anything
different than what i am doing…

code>
require ‘uri’
require ‘net/http’

module ModuleX

class Parser
def self.getData(d)
htmldata = self.loadData(d)
end
private
def self.loadData(profile)
url=’’
htmldata = Net::HTTP.get(URI.parse(url))
htmldata.to_s
end
end

end

i advance thanks for shading liggt

On Oct 27, 2009, at 2:32 PM, Vic P.h. wrote:

i got a module x and then a class z and inside this class i do a
Net::HTTP call and it looks for it inside module x … and i am
clueless…

i get uninitialized constant ModuleX::Net::HTTP

I couldn’t replicate that error using your code in ruby 1.8.7 or
in ruby 1.9. What version are you using?

In any case, you can always force constants to be resolved
from the top level by preceding them with two colons:

::Net::HTTP

Gary W.

Hi –

On Wed, 28 Oct 2009, Vic P.h. wrote:

and it dosent look like it does anything
def self.getData(d)
htmldata = self.loadData(d)
end
private
def self.loadData(profile)

That private directive isn’t doing what you think. It governs instance
methods, but you’re defining class methods. If you want a private
class method, you need to declare it private in the class’s singleton
class:

class C
private
def self.talk
puts “hi”
end
class << self
private
def talk_privately
puts “hi privately”
end
end
end

C.talk # “hi”
C.talk_privately # error

 url=''
 htmldata = Net::HTTP.get(URI.parse(url))
 htmldata.to_s

end
end

end

Like Gary, I can’t replicate the constant error you’re getting.

David


The Ruby training with D. Black, G. Brown, J.McAnally
Compleat Jan 22-23, 2010, Tampa, FL
Rubyist http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)

Mex Noob Y. wrote:

i got a module x and then a class z and inside this class i do a
Net::HTTP call and it looks for it inside module x … and i am
clueless…

i get uninitialized constant ModuleX::Net::HTTP

Almost certainly you forgot the “require ‘net/http’” in the actualy code
you’re using, or else you have a typo in the ‘Net’ or ‘HTTP’.

Ruby tries both Net::HTTP and ModuleX::Net::HTTP, and will only give
this error if both don’t exist. Hence I don’t believe that you have
actually loaded Net::HTTP.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs