# Accessing Kernel namespace from within classes

**URL:** <https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009>\
**Category:** Ruby\
**Created:** [October 1, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009 "2007-10-01T16:37:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 1, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/1 "2007-10-01T16:37:25Z")

</div>

Hi all

Hoping someone could tell me the answer to the following.

I have a class defined in a file: TestWebsite. The main program  
requires the ‘net/http’ library and also the TestWebsite file. The  
class “TestWebsite” contains several class methods that use things  
such as “Net::HTTP.get\_response()” however I get the following errors:

/net/http.rb:380:in `get_response': undefined method`request\_uri’  
for #\<URI::Generic:0x2d3b9c URL:example.com\> (NoMethodError)  
from /opt/local/lib/ruby/1.8/net/http.rb:543:in `start' from /opt/local/lib/ruby/1.8/net/http.rb:379:in`get\_response’  
from ./test\_website.rb:10:in `test’

It’s my guess the the class methods aren’t able to access the net/  
http library which is in the kernel namespace, if this is true then  
what must I do to allow them access?

Many thanks,

Gabriel

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 1, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/2 "2007-10-01T17:10:59Z")

</div>

On Oct 1, 8:35 am, Gabriel D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> for #\<URI::Generic:0x2d3b9c URL:example.com\> (NoMethodError)  
> Gabriel  
> Are you using a complete URI or just part of one? For example,  
> ‘[domain.com](http://domain.com)’ is not a URI. Further:

[root@server15 mwhite]# ruby -r uri -e ‘p  
URI.parse(“[google.com](http://google.com)”).host’  
nil  
[root@server15 mwhite]# ruby -r uri -e ‘p URI.parse(“http://  
[google.com](http://google.com)”).host’  
“[google.com](http://google.com)”

If that’s not the problem, maybe you could give us some code? Good  
luck!

Matt

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 1, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/3 "2007-10-01T17:51:23Z")

</div>

On 1 Oct 2007, at 16:10, Matt W. wrote:

> If that’s not the problem, maybe you could give us some code? Good  
> luck!

Oh thank you so much, you spotted that one a million miles off, I  
missed out the http://. Have corrected this but now getting errors like:  
./test\_website.rb:13:in `test’: uninitialized constant  
TestWebsite::NET (NameError)  
MMM something to keep my mind ticking over.

Many thanks

Gabriel

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 1, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/4 "2007-10-01T18:46:04Z")

</div>

On Oct 1, 9:50 am, Gabriel D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [root@server15 mwhite]# ruby -r uri -e 'p URI.parse("http://  
> > MMM something to keep my mind ticking over.
> 
> Many thanks
> 
> Gabriel

No problem. If you need more help, be sure to give us the code that is  
causing the error and not just the error.

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 3, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/5 "2007-10-03T12:32:51Z")

</div>

On 1 Oct 2007, at 17:45, Matt W. wrote:

> > > nil  
> > > /test\_website.rb:13:in `test’: uninitialized constant

Thanks, Matt!

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 1, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/6 "2007-10-01T23:09:11Z")

</div>

On Oct 1, 2007, at 11:50 AM, Gabriel D. wrote:

> Oh thank you so much, you spotted that one a million miles off, I  
> missed out the http://. Have corrected this but now getting errors  
> like:  
> ./test\_website.rb:13:in `test’: uninitialized constant  
> TestWebsite::NET (NameError)  
> MMM something to keep my mind ticking over.

You can force constants to be evaluated from the  
top-level rather than from the current lexical scope by  
prefixing the constant with ‘::’

class TestSuite  
ok = ::Net::HTTPOK  
end

Gary W.

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [October 3, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/accessing-kernel-namespace-from-within-classes/116009/7 "2007-10-03T12:34:36Z")

</div>

On 1 Oct 2007, at 22:07, Gary W. wrote:

> top-level rather than from the current lexical scope by  
> prefixing the constant with ‘::’
> 
> class TestSuite  
> ok = ::Net::HTTPOK  
> end
> 
> Gary W.

Thank you, Gary!
