From: "David A. Black" Date: 2004-09-28T06:07:01+09:00 Subject: Re: {newb} Each statements Hi -- On Tue, 28 Sep 2004, Bill Guindon wrote: > On Tue, 28 Sep 2004 05:13:30 +0900, STEPHEN BECKER I V > wrote: > > Do each statements change the thing that they are using? > > data is a a string. > > no, but map! and collect! do, but they only work on Arrays, not > Strings. So first, you'll need to split the string into an Array... > for strings, each_byte will do that. > > srand(5000) > ndata = '' > a = data.size-1 > data.each_byte do |c| > ndata += (((c-97)+rand(10))%26).chr > end That's a bit inefficient, because each time through you're creating a new string in ndata. You could use << to append instead. David -- David A. Black dblack@wobblini.net