From: Robert Klemme Date: 2007-10-31T22:06:46+09:00 Subject: Re: Can we define data types explicitly? 2007/10/31, Shuaib Zahda : > Hi > > I am working on application that emphasizes on the data types of the > data. The application reads a line from the user by the prompt. then it > divides the entry into parts based on comma separator. > e.g > > f = gets > "apple", 5, 8.9, "red" > > after i split them in an array > > arr = f.split(", ") > > they will be all converted into string and stored in arr as elements of > array. > I need to check whether the type of 5 is integer or not, 8.9 is float, > etc. In this case it is fine but in the case that the user keys in > string instead of float. the methods to_i, to_f will convert the string > into 0 and assume it is of that type. > > Is there any mechanism that allows me to check the data type ? 13:57:22 /cygdrive/c/SCMws/RKlemme$ ruby -e 'Integer("rubbish")' -e:1:in `Integer': invalid value for Integer: "rubbish" (ArgumentError) from -e:1 14:06:07 /cygdrive/c/SCMws/RKlemme$ Kind regards robet -- use.inject do |as, often| as.you_can - without end