Newbie 1.8.7 to 1.9.1 problem

Several scripts that used to work now don’t. I had not used ruby or any
of
these scripts for several months. In the meantime i upgraded vista to
windows 7 (clean install) and decided to install 1.9.1 rather than the
1.8.7 i used previously.

And now here’s the problem i have:

f = open("http…
webpage = f.read

dump = webpage.sub(%r{<body.?>(.?)…

process the rest line-by-line

dump.each do |eachline| # this line produces this error:
… :in block in <main>': undefined methodeach’ for
#String:0x1f3f620 (NoMethodError)

I guess its telling me dump is a string and you can’t do “string”.each
But i don’t understand why this–and several similar–scripts DID WORK
with Ruby 1.8.7 So 1.8.7 would “split up” dump at every newline (CR/LF)
but 1.9.1 will not…???

Can someone tell me what’s going on, and what i should try to get these
to work
with 1.9.1?

Thanks!

On Sat, Jun 12, 2010 at 11:38 AM, Phil Richards
[email protected] wrote:


but 1.9.1 will not…???

Can someone tell me what’s going on, and what i should try to get these
to work
with 1.9.1?

iota ~ % irb

“”.methods.grep(/each/)
=> [:each_line, :each_byte, :each_char, :each_codepoint]
“”.is_a?(Enumerable)
=> false

On 12.06.2010 04:38, Phil Richards wrote:


but 1.9.1 will not…???

Can someone tell me what’s going on, and what i should try to get these
to work
with 1.9.1?

You just need to replace #each with #each_line and be done. I believe
the background of this is that 1.9 tries do it a bit better than 1.8
which assumed every String is an Enumerable of lines instead of
characters which would be more natural.

Kind regards

robert

Phil Richards wrote:

I guess its telling me dump is a string and you can’t do “string”.each

Correct: String#each was removed from 1.9

But i don’t understand why this–and several similar–scripts DID WORK
with Ruby 1.8.7 So 1.8.7 would “split up” dump at every newline (CR/LF)
but 1.9.1 will not…???

That’s right.

ruby 1.9 is a substantially different language than 1.8, both in terms
of its implementation (YARV engine) and its language specification (e.g.
total change to how Strings work). You might not infer this from the
“minor” version bump, but it’s the case.

Can someone tell me what’s going on, and what i should try to get these
to work
with 1.9.1?

You’ll have to take it case-by-case. For example, use String#each_line
here. (Incidentally, I can see no logical reason for removing
String#each but not removing IO#each)

The good news is that the 1.8 language remains alive and well, so you
can just stick with that.