From: Timothy Hunter Date: 2005-12-22T08:17:49+09:00 Subject: Re: String > Integer Conversion Problem Matthew Feadler wrote: > Retro thanks to all who helped me with my last post. I'm certainly more > comfortable with Ruby now than then, but still a newbie as the following > will surely demonstrate. > > Below, you can see that I'm checking command-line arguments to the > program for various conditions. Unfortunately, because the args are > stored as strings, when I convert them via to_i, empty and non-numerical > strings become 0. 0 is an acceptable element in this program, therefore > I can't use it to test for invalid input. I've worked around this (sort > of), by creating two sets of variables for the arguments (one set as > strings, one set as integers). Unfortunately, this complicates the > code, and more importantly, leaves me stumped concerning how to test for > non-numeric values. The Integer() method raises ArgumentError if given an empty, non-numeric, or otherwise non-well-formed string.