September 26th, 2010, 10:36 PM
Join Date: Sep 2010
Time spent in forums: 26 m 7 sec
Reputation Power: 0
Checking the type of class
Hi, I'm new to Ruby and new to this forum, so apologies if I'm going against normal forum proceadures in my post (I have read the 'read this first' bit)
Anyway I'm playing around with methods. I want to be able to check the class of a variable and make a decision on the result. When I test my method in irb it works but when I run it in a file it takes no effect. Here is what I tested in irb mode......
five = 5
Here's my method in the file......
if pricex.class.eql? (Fixnum)
then error("wrong type")
else true end
If I type in a fixnum into the command line it fails the condition test.
The output does not give me "wrong type"
Any ideas? Thanks