From: Robert Klemme Date: 2013-02-20T01:57:00+09:00 Subject: Re: Adding camelize and underscore to String On Tue, Feb 19, 2013 at 4:45 AM, Josh Cheek wrote: > On Mon, Feb 18, 2013 at 9:23 PM, tamouse mailing lists > wrote: >> >> I do this a bit differently: >> >> class String >> def camelize >> self = self.dup >> self.camelize! >> end > > Should just be: > def camelize > dup.camelize! > end I'd do def camelize dup.tap {|s| s.camelize!} end or even def camelize dup.tap &:camelize! end Because usually #camelize! would return nil if the String was left unchanged. In any case, this construct would make #camelize robust against changes in #camelize!'s return value. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/