Undefined constant/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…

this is being called from a file inside lib/

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

in advance thanks for shading light

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

[…]

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

Right. Since you’re in ModuleX, everything is assumed to be in the
scope of ModuleX unless fully qualified. So Parser is ModuleX::Parser
(which is what you want), and Net::HTTP is ModuleX::Net::HTTP (which you
don’t want). To force global scope on Net::HTTP, just qualify it by
prefixing the scope operator, so you’d write it as ::Net::HTTP.

in advance thanks for shading light

You’re welcome!

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

you sir rock!
again thanks!