# Scope Missunderstanding

**URL:** <https://www.ruby-forum.com/t/scope-missunderstanding/177998>\
**Category:** Ruby\
**Created:** [October 27, 2009, 7:32pm UTC](https://www.ruby-forum.com/t/scope-missunderstanding/177998 "2009-10-27T19:32:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mex\_Noob\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Mex\_Noob\_Y](https://www.ruby-forum.com/u/Mex_Noob_Y)\
**Post date:** [October 27, 2009, 7:32pm UTC](https://www.ruby-forum.com/t/scope-missunderstanding/177998/1 "2009-10-27T19:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mex\_Noob\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Mex\_Noob\_Y](https://www.ruby-forum.com/u/Mex_Noob_Y)\
**Post date:** [October 27, 2009, 10:02pm UTC](https://www.ruby-forum.com/t/scope-missunderstanding/177998/2 "2009-10-27T22:02:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mex\_Noob\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Mex\_Noob\_Y](https://www.ruby-forum.com/u/Mex_Noob_Y)\
**Post date:** [October 27, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/scope-missunderstanding/177998/3 "2009-10-27T22:09:50Z")

</div>

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](http://www.thecompleatrubyist.com)

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

---

<div class="post-metadata">

**Author:** ![Mex\_Noob\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Mex\_Noob\_Y](https://www.ruby-forum.com/u/Mex_Noob_Y)\
**Post date:** [October 28, 2009, 10:54am UTC](https://www.ruby-forum.com/t/scope-missunderstanding/177998/4 "2009-10-28T10:54:43Z")

</div>

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.
