From: Colin Bartlett Date: 2008-05-08T17:43:09+09:00 Subject: Re: to check for numericality ------=_Part_14462_17462595.1210236188976 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/8/08, Farrel Lifson wrote: > > @val = someValue if ( Integer( someValue) rescue Float( someValue ) > rescue false) > > 2008/5/8 Sijo Kg : > > > Hi > > I have > > @val=SomeValue #for example 00,02,aa > > How can I check @val contains only numeriacal(including zero) > > values..I have to avoid aa above (for example ) > > > > Sijo > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > Well that's two (or three) very useful things I didn't know. (I have the first edition of Programming Ruby.) I didn't know you could use "rescue" without "begin" and "end", and I didn't know you could use "Integer" and "Float" to test whether the *whole* of a string would convert to a number. In this situation is there any advantage to testing for "Integer" first, instead of just using newval = someValue if ( Float( someValue ) rescue false ) ------=_Part_14462_17462595.1210236188976--