From: "David A. Black" Date: 2005-08-08T23:56:08+09:00 Subject: Re: String#to_ary and Test::Unit --8323328-937761061-1123512965=:7838 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-937761061-1123512965=:7838" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-937761061-1123512965=:7838 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 8 Aug 2005, [ISO-8859-1] Brian Schr=F6der wrote: > On 08/08/05, Trans wrote: >> >> David A. Black wrote: >>> This message is in MIME format. The first part should be readable text= , >>> while the remaining parts are likely unreadable without MIME-aware to= ols. >>> >>> Hi -- >>> >>> On Mon, 8 Aug 2005, [ISO-8859-1] Brian Schr=F6der wrote: >>> >>>> Another sidenote that removes the need for to_ary completely and is a >>>> lot faster: >>> >>> It's not needed if it's OK just to call #each, but I thought the >>> #to_ary call was part of Tom's original requirement. >> >> Unfortunately David is correct. In looking more closely at your >> (Brian's) code offering, I see that it still uses #each. So in the >> context of String, the same problem arsies --I can't count on a string >> being iterated over by chars. I'll have to create an overriding #freq >> method specifically for string --and the other methods that work the >> same way. >> >> T. >> >> > > Yes, but why not use: > > probability_hash =3D "this is my string".split(//).freq > > Each object that could support to_ary can also support each, while not > every object that has an each makes sense with to_ary. So it would > seem better to me to put this functionality into the enumerable and > supply an enumerable. I got the impression Tom was just trying to make things as transparent as possible (though given the String#to_ary infinite loop, transparent as possible may not be very transparent). > Then you can even do > > module CharString > def each(&block) > self.split(//).each &block > end > end > > module WordString > def each(&block) > self.split(/\s+/).each &block > end > end > > charstring =3D "some chars" > class << charstring > include CharString > end I thought you disliked the "<<" notation :-) charstring.extend(CharString) David --=20 David A. Black dblack@wobblini.net --8323328-937761061-1123512965=:7838-- --8323328-937761061-1123512965=:7838--