From: Martin DeMello Date: 2002-03-04T06:17:05+09:00 Subject: Re: string to array and back Ron Jeffries wrote: > In Ruby, an array of bytes is really an array of objects that behave like > Fixnum, if I'm not mistaken. Send it :each and you get the bytes one after > another. But a string mistakenly thinks that :each should deliver in > lines, not bytes. Gack. > An array of bytes sent :to_a answers itself. A string sent :to_a answers, > get this, an array with the string in it. (Or lots of strings, if the > string has newlines in it.) Gack. class String alias each each_byte end seems to fix both problems, with String#each_line retaining the original definition of 'each'. (Why doesn't setting $/ to '' do the same, incidentally? It seems like less surprising behaviour than the "append multiple successive newlines" special case.) -- Martin DeMello