------art_135305_7726285.1156520578276
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 8/25/06, Gennady Bystritsky <Gennady.Bystritsky / quest.com> wrote:
>
> > >> On Fri, 25 Aug 2006, Jeremy Lizt wrote:
> > >>
> > >>> Thanks to everyone for the quick response. The Integer
> > >> suggestion works
> > >>> great, but I'll point out one wrinkle that I encountered:
> > >>>
> > >>> Integer nil # => 0
> > >>>
> > >>> That was a small surprise. (These zeros keep popping up
> > when you may
> > >>> not expect them!) My little conversion method now works
> > >> fine and looks
> > >>> like this:
> > >>>
> > >>>  def string_to_i(str)
> > >>>    if str.nil? then return nil else Integer str end
> > >>>  rescue nil
> > >>>  end
> > >>
> > >> I can't resist:
> > >>
> > >>    def string_to_i(str)
> > >>      Integer(str) rescue nil unless str.nil?
> > >>    end
> > >>
> > >> :-)
> > >
> > > Likewise ;-)
> > >
> > > def string_to_i(str)
> > >  str and Integer(str) rescue nil
> > > end
> >
> > The only reason I like mine better than yours is that mine gives nil
> > for false, whereas yours gives false.  (Possibly not a big problem in
> > practice, though :-)
>
> You win :-) -- I like yours too, acrually. Simply could not resist, as
> you nicely put it ;-).
>
> Gennady.
>
>
Let us get rid of the evil if/unless though

( x and Integer(str) rescue nil ) or nil

Well spent time and bandwith again ;)

Robert
-- 
Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

------art_135305_7726285.1156520578276--