From: Phrogz Date: 2007-03-27T08:25:04+09:00 Subject: Re: adding anotehr each method to String On Mar 26, 4:53 pm, "Rick DeNatale" wrote: > On 3/25/07, Une B�vue wrote: > > s='toto' > > s.to_a > > # => ['toto'] > > This is because in Ruby a String doesn't act as a collection of > characters, it acts as a collection of lines. > > s = "to\nto" > s.to_a => ["to\n", "to"] To be pedantic, it's not really a collection of lines. It's a collection of stuff-terminated-by-some-arbitrary-character-sequence. The global variable $/ holds this special string: >> $/ => "\n" >> s = "foo-bar\njim-jam" => "foo-bar\njim-jam" >> s.to_a => ["foo-bar\n", "jim-jam"] >> $/ = '-' => "-" >> s.to_a => ["foo-", "bar\njim-", "jam"] >> $/ = "bar" => "bar" >> s.to_a => ["foo-bar", "\njim-jam"]