On Tue, Feb 19, 2013 at 4:45 AM, Josh Cheek <[email protected]> wrote:
> On Mon, Feb 18, 2013 at 9:23 PM, tamouse mailing lists
> <[email protected]> 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/
--
[email protected] |
https://groups.google.com/d/forum/ruby-talk-google?hl=en
---
You received this message because you are subscribed to the Google Groups
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.