Save only first line from string?

On Mon, Oct 4, 2010 at 4:19 AM, Terry M. [email protected]
wrote:

Hi. What’s the most simple and elegant way to remove all the contents of
a String except for the first line? (Assume string consist of one line,
multiple lines, or no lines, and assume that we don’t know which OS we
are on.)

irb(main):005:0> s = “multiple\nlines\n”
=> “multiple\nlines\n”
irb(main):006:0> s[/^.$/]
=> “multiple”
irb(main):007:0> s[/^.
?$/]
=> “multiple”

Cheers

robert