Hacker News new | ask | show | jobs
by kyberias 3741 days ago
Out of curiosity (haven't done ruby for awhile): is your line-by-line implementation safe? Is it guaranteed that the lines are identical in the output file besides the character you're replacing? I'm thinking different CR+LR combinations. What if the final line is not terminated by newline? Doesn't print always add it?
1 comments

You're thinking of 'puts' which appends a newline.

'print' does not

The code does handle/preserve all the cases you mentioned (\r\n, final or no final terminating newline, etc).