From: "David A. Black" Date: 2009-07-01T20:44:04+09:00 Subject: Re: Making a random string Hi -- On Wed, 1 Jul 2009, Eleanor McHugh wrote: > On 1 Jul 2009, at 06:57, Brian Candler wrote: >> Robert Klemme wrote: >>>> s.upcase >>> >>> You can probably squeeze out a bit performance especially for large >>> strings by replacing this with "s.upcase!; s". >> >> A very bad idea IMO. Why make your code larger and less readable for the >> sake of perhaps one microsecond or less? If performance matters on this >> microscopic scale, you should be writing in C. > > > I agree that "s.upcase!; s" is ugly, and I really wish the bang methods > returned self on success and raised an exception on error as that's closer to > how I use them than the current approach, but it's still a well-established > idiom and hardly likely to confuse even a neophyte so long as they bother to > RTFM. I don't think the distinction is between success and failure, though. (str="ABC").upcase! succeeds -- it just doesn't change str. (I'm not a huge fan of the nil returns either, by the way.) Of course there's always: str = "ABC" str.tap(&:upcase!) :-) David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) "Ruby 1.9: What You Need To Know" Envycasts with David A. Black http://www.envycasts.com