I'm running irb as a one-off text preprocessing tool. I ran into immediate trouble just printing the text.
foo = File.open "bar"
foo.each_line {|l| puts l}
This prints as intended and returns #<File:emails plaintext>
.
However, if I call #each_line
again on the same object, no printing occurs, though it still returns #<File:emails plaintext>
.
Why are the contents of the File
object being overwritten by a call to #each_line
? I thought the raison d'etre of #each
-like methods was to ensure mutation does not occur. What is the proper 'ruby way' to do this?