# Newbie 1.8.7 to 1.9.1 problem

**URL:** <https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053>\
**Category:** Ruby\
**Created:** [June 12, 2010, 4:38am UTC](https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053 "2010-06-12T04:38:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philippeqc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@philippeqc](https://www.ruby-forum.com/u/philippeqc)\
**Post date:** [June 12, 2010, 4:38am UTC](https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053/1 "2010-06-12T04:38:46Z")

</div>

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 method`each’ 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!

---

<div class="post-metadata">

**Author:** ![philippeqc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@philippeqc](https://www.ruby-forum.com/u/philippeqc)\
**Post date:** [June 12, 2010, 4:54am UTC](https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053/2 "2010-06-12T04:54:10Z")

</div>

On Sat, Jun 12, 2010 at 11:38 AM, Phil Richards  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![philippeqc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@philippeqc](https://www.ruby-forum.com/u/philippeqc)\
**Post date:** [June 12, 2010, 3:20pm UTC](https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053/3 "2010-06-12T15:20:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![philippeqc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@philippeqc](https://www.ruby-forum.com/u/philippeqc)\
**Post date:** [June 12, 2010, 9:13pm UTC](https://www.ruby-forum.com/t/newbie-1-8-7-to-1-9-1-problem/190053/4 "2010-06-12T21:13:02Z")

</div>

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.
