From: Ross Bamford Date: 2005-12-22T21:32:59+09:00 Subject: Re: String > Integer Conversion Problem On Thu, 22 Dec 2005 04:20:04 -0000, James Edward Gray II wrote: > On Dec 21, 2005, at 6:13 PM, Jacob Fugal wrote: > >> On 12/21/05, Timothy Hunter wrote: >>> The Integer() method raises ArgumentError if given an empty, >>> non-numeric, or otherwise non-well-formed string. >> >> On 12/21/05, James Edward Gray II wrote: >>> if ARGV.all? { |n| n =~ /\A\d+\Z/ } >>> puts "Usage..." >>> exit >>> else >>> one, two = ARGV.map { |n| Integer(n) } >>> end >> >> So could we rewrite this as: >> >> begin >> one, two = ARGV.map{ |n| Integer(n) } >> rescue ArgumentError >> puts Usage >> exit >> end > > Yeah, that's better. Neither of our versions checks the number of > arguments though and we probably should... > I'm just wondering, in Java it's a bit of a no-no using exceptions like this (since they're pretty heavy to put together). Is it the case in Ruby? And does that regexp match balance it out anyway? -- Ross Bamford - rosco@roscopeco.remove.co.uk