[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Uninitialized constant: String::StringIO

Patrick Li

8/14/2008 4:43:00 PM

Hi,
I'm having a hard time spotting my bug in this code.
When it runs it gives me:
uninitialized constant String::StringIO (NameError)

Am I missing something? StringIO is a global constant. Why can't ruby
find it?

class String
def self.fromURL(string)
string = string.string if string.is_a?(StringIO)
CGI.unescape(string)
end
end

Thanks a lot for your help
-Patrick
--
Posted via http://www.ruby-....

5 Answers

ara.t.howard

8/14/2008 4:50:00 PM

0


On Aug 14, 2008, at 10:43 AM, Patrick Li wrote:

> Hi,
> I'm having a hard time spotting my bug in this code.
> When it runs it gives me:
> uninitialized constant String::StringIO (NameError)
>
> Am I missing something? StringIO is a global constant. Why can't ruby
> find it?
>
> class String
> def self.fromURL(string)
> string = string.string if string.is_a?(StringIO)
> CGI.unescape(string)
> end
> end
>
> Thanks a lot for your help
> -Patrick
> --
> Posted via http://www.ruby-....
>


require 'stringio'

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Robert Klemme

8/14/2008 4:57:00 PM

0

On 14.08.2008 18:43, Patrick Li wrote:
> Hi,
> I'm having a hard time spotting my bug in this code.
> When it runs it gives me:
> uninitialized constant String::StringIO (NameError)
>
> Am I missing something? StringIO is a global constant. Why can't ruby
> find it?
>
> class String
> def self.fromURL(string)
> string = string.string if string.is_a?(StringIO)
> CGI.unescape(string)
> end
> end

$ ruby -e 'p StringIO'
-e:1: uninitialized constant StringIO (NameError)

robert@fussel ~
$ ruby -r stringio -e 'p StringIO'
StringIO

robert@fussel ~
$

Kind regards

robert

Patrick Li

8/14/2008 4:57:00 PM

0

Thanks Ara,

Just out of curiosity, why is it that I need
require "stringio" when running as a script under Apache, but not when I
run under irb?

Is there a way to tell when I need to require a library and when I
don't? (ie. from documentation, etc...)
--
Posted via http://www.ruby-....

ara.t.howard

8/14/2008 5:18:00 PM

0


On Aug 14, 2008, at 10:57 AM, Patrick Li wrote:

> Thanks Ara,
>
> Just out of curiosity, why is it that I need
> require "stringio" when running as a script under Apache, but not
> when I
> run under irb?
>
> Is there a way to tell when I need to require a library and when I
> don't? (ie. from documentation, etc...)

irb simply had already required it. there is no general way to tell
but, in this case you could check $LOADED_FEATURES

or, more simply

require 'stringio' unless defined?(StringIO)

but the require never hurts so just do it anyhow

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Patrick Li

8/14/2008 5:21:00 PM

0

Okay, I'll keep that in mind.
Thanks for your help Ara, and Klemme
--
Posted via http://www.ruby-....