From: Timothy Gregory Date: 2013-02-20T18:38:42+09:00 Subject: Re: Adding camelize and underscore to String --20cf306f72267022a804d624b381 Content-Type: text/plain; charset=ISO-8859-1 hi may i ask is it the ruby method? active_support inflections camelize "allows you to specify acronyms in config/initializers/inflections.rb" timo On Wed, Feb 20, 2013 at 6:32 AM, Josh Cheek wrote: > On Tue, Feb 19, 2013 at 10:57 AM, Robert Klemme < > shortcutter@googlemail.com> wrote: > >> 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. >> >> > I guess I wouldn't ever implement camelize! to return nil. I checked > ActiveSupport, and it is apparently not a method. > > -Josh > --20cf306f72267022a804d624b381 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
hi
may i ask
is it=A0the ruby m= ethod?
active_support=A0
inflections
cam= elize
"allows you to specify acronyms in config= /initializers/inflections.rb"
timo


On Wed, Feb 20, 2013 at 6:32 AM, Jos= h Cheek <josh.cheek@gmail.com> wrote:
On Tue, Feb 19, 2013 at 10:57 AM, Robert Klemme = <shortcutter@googlemail.com> wrote:
On Tue, Feb 19, 2013 at 4:45 AM, Josh Cheek <josh.cheek@gmail.com> wrote:
> On Mon, Feb 18, 2013 at 9:23 PM, tamouse mailing lists
> <tamou= se.lists@gmail.com> wrote:
>>
>> I do this a bit differently:
>>
>> class String
>> =A0 def camelize
>> =A0 =A0 self =3D self.dup
>> =A0 =A0 self.camelize!
>> =A0 end
>
> Should just be:
> def camelize
> =A0 dup.camelize!
> end

I'd do

def camelize
=A0 dup.tap {|s| s.camelize!}
end

or even

def camelize
=A0 dup.tap &:camelize!
end

Because usually #camelize! would return nil if the String was left
unchanged. =A0In any case, this construct would make #camelize robust
against changes in #camelize!'s return value.


I guess I wouldn'= ;t ever implement camelize! to return nil. I checked ActiveSupport, and it = is apparently not a method.

-Josh

--20cf306f72267022a804d624b381--