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
On Aug 14, 2008, at 10:43 AM, Patrick Li wrote:
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/.
require ‘stringio’
a @ http://codeforpeople.com/
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…)
On 14.08.2008 18:43, Patrick Li wrote:
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
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://codeforpeople.com/
Okay, I’ll keep that in mind.
Thanks for your help Ara, and Klemme