From: Christopher Swasey Date: 2008-03-12T12:43:59+09:00 Subject: Re: "".to_a isn't consistent with "string".to_a On 3/11/08, Clifford Heath wrote: > I've just been tripped up by this behaviour, which I haven't > seen documented anywhere: > > "hello".to_a #=> ["hello"] > "".to_a #=> [] > > Why does an empty string get omitted from the array? > Why doesn't Enumerable#to_a document this behaviour of strings? > This is completely broken (Ruby 1.8.6) I disagree. #to_a doesn't just encase the string object in an otherwise empty array, rather it casts the string to an array, as appropriate: "".to_a => [] "test".to_a => ["test"] "this\nis\na\n\test".to_a => ["this\n", "is\n", "a\n", "test"] The array equivalent of an empty string is an empty array. Both, for instance, have a #size of 0. Christopher