[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Accessing Kernel namespace from within classes...

Gabriel Dragffy

10/1/2007 2:36:00 PM

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



6 Answers

Matt White

10/1/2007 3:10:00 PM

0

On Oct 1, 8:35 am, Gabriel Dragffy <g...@dragffy.com> wrote:
> 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

Are you using a complete URI or just part of one? For example,
'domain.com' is not a URI. Further:

[root@server15 mwhite]# ruby -r uri -e 'p
URI.parse("google.com").host'
nil
[root@server15 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

Gabriel Dragffy

10/1/2007 3:50:00 PM

0


On 1 Oct 2007, at 16:10, Matt White wrote:
>
> Are you using a complete URI or just part of one? For example,
> 'domain.com' is not a URI. Further:
>
> [root@server15 mwhite]# ruby -r uri -e 'p
> URI.parse("google.com").host'
> nil
> [root@server15 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!

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


Matt White

10/1/2007 4:41:00 PM

0

On Oct 1, 9:50 am, Gabriel Dragffy <g...@dragffy.com> wrote:
> On 1 Oct 2007, at 16:10, Matt White wrote:
>
>
>
> > Are you using a complete URI or just part of one? For example,
> > 'domain.com' is not a URI. Further:
>
> > [root@server15 mwhite]# ruby -r uri -e 'p
> > URI.parse("google.com").host'
> > nil
> > [root@server15 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!
>
> 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

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

Gary Wright

10/1/2007 9:08:00 PM

0


On Oct 1, 2007, at 11:50 AM, Gabriel Dragffy 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 Wright

Gabriel Dragffy

10/3/2007 10:32:00 AM

0


On 1 Oct 2007, at 17:45, Matt White wrote:

> On Oct 1, 9:50 am, Gabriel Dragffy <g...@dragffy.com> wrote:
>> On 1 Oct 2007, at 16:10, Matt White wrote:
>>
>>
>>
>>> Are you using a complete URI or just part of one? For example,
>>> 'domain.com' is not a URI. Further:
>>
>>> [root@server15 mwhite]# ruby -r uri -e 'p
>>> URI.parse("google.com").host'
>>> nil
>>> [root@server15 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!
>>
>> 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
>
> No problem. If you need more help, be sure to give us the code that is
> causing the error and not just the error.
>
>

Thanks, Matt!


Gabriel Dragffy

10/3/2007 10:32:00 AM

0


On 1 Oct 2007, at 22:07, Gary Wright wrote:

>
> On Oct 1, 2007, at 11:50 AM, Gabriel Dragffy 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 Wright
>

Thank you, Gary!