# Undefined constant/Scope Missunderstanding

**URL:** <https://www.ruby-forum.com/t/undefined-constant-scope-missunderstanding/178001>\
**Category:** Rails\
**Created:** [October 27, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/undefined-constant-scope-missunderstanding/178001 "2009-10-27T19:58:01Z")\
**Posts on this page:** 3\
**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:58pm UTC](https://www.ruby-forum.com/t/undefined-constant-scope-missunderstanding/178001/1 "2009-10-27T19:58:01Z")

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

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

---

<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, 8:16pm UTC](https://www.ruby-forum.com/t/undefined-constant-scope-missunderstanding/178001/2 "2009-10-27T20:16:44Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<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, 8:24pm UTC](https://www.ruby-forum.com/t/undefined-constant-scope-missunderstanding/178001/3 "2009-10-27T20:24:39Z")

</div>

you sir rock!  
again thanks!
