Question: I have a string in Ruby, `s` (say) which might have any of the standard line endings (`\n`, `\r\n`, `\r`). I want to convert all of those to `\n`s. What's the best way?

This seems like a super-common problem, but there's not much documentation about it. Obviously there are easy crude solutions, but is there anything built in to handle this? 

*Elegant, idiomatic-Ruby solutions are best.*

EDIT: realized that `^M` and `\r` are the same. But there are still three cases. (See [wikipedia](http://en.wikipedia.org/wiki/Newline#Representations).)

Answer: 
I think the cleanest solution would be to use a regular expression:

```
s.gsub! /\r\n?/, "\n"

```
Try opening them on NetBeans IDE - Its asked me before, on one of the projects I've opened from elsewhere, if I wanted to fix the line endings. I think there might be a menu option to do it too, but that would be the first thing I would try.