Hi --

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

:-)


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black     => book, Ruby for Rails
http://www.rubycentral.org       => Ruby Central, Inc.