Re: str1 = str2 is not a copy?!?

From: Austin Z. [mailto:[email protected]]

BTW, is there a foreach function that automatically strips off the
newlines from line? Returning the record separators is silly.

No, it isn’t silly. Sometimes, that’s what people want. You should be
using #chomp or #chomp! to strip that (use #strip or #strip!
if and only if you want to remove whitespace from beginning and end of
the line).

I would argue that this claim is subjective. I personally feel that it
is silly, akin to if String#split left the delimiters at the end of each
match.

(And there’s one answer, Joe. If you can handle slurping the whole file
into memory, perhaps instead use something like:
IO.read( data_file ).split( $/ ).each{ |line| … }
to process your data.)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs