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-forum.com/.
a11
(-a)
2
require 'stringio'
a @ http://codeforpeople.com/
···
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-forum.com/\.
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
$ ruby -e 'p StringIO'
-e:1: uninitialized constant StringIO (NameError)
robert@fussel ~
$ ruby -r stringio -e 'p StringIO'
StringIO
robert@fussel ~
$
Kind regards
robert
···
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
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-forum.com/.
a11
(-a)
5
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://codeforpeople.com/
···
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...)
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
Okay, I'll keep that in mind.
Thanks for your help Ara, and Klemme
···
--
Posted via http://www.ruby-forum.com/.