[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Best way to handle Integer/Bignum/Fixnum
From: Eric Wong <e () 80x24 ! org>
Date: 2017-02-21 9:52:21
Message-ID: 20170221095221.GA14202 () starla
[Download RAW message or body]
Samuel Williams <space.ship.traveller@gmail.com> wrote:
> On 20 February 2017 at 23:40, Eric Wong <e@80x24.org> wrote:
> > a) if Integer === foo
> > ...
> >
> > b) if foo.kind_of?(Integer)
> > ...
> >
> > c) case foo
> > when Integer
> > ...
> >
<top-posting corrected>
> If you use the name of the class in any way... Your suggestion gave me
> the idea to check how xml_mini.rb works.. now they "fixed" it.
>
> https://github.com/rails/rails/blob/71da39097b67114329be6d8db7fe6911124531af/activesupport/lib/active_support/xml_mini.rb#L35-L53
>
> It's a git ugly, is that the best we can do?
Unless TYPE_NAMES hash is used elsewhere, I don't think they
need to be using that hash... They can use the case/when I
described in c) above.
Calling foo.class.name also generates short-lived garbage
strings if that code path is called frequently. Checking
#kind_of? and === (via case/when) won't make garbage.
Anyways I don't use Rails or centralized/proprietary messaging
systems; but maybe somebody who does can rework the code to
be version-independent and generate less garbage at the same
time...
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic