Accessing Kernel namespace from within classes

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 methodrequest_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:inget_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

On Oct 1, 8:35 am, Gabriel D. [email protected] 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’ is not a URI. Further:

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

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

Matt

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

On Oct 1, 9:50 am, Gabriel D. [email protected] wrote:

[[email protected] 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.

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

nil
/test_website.rb:13:in `test’: uninitialized constant

Thanks, Matt!

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.

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!

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