September 26th, 2010, 10:36 PM
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 I type in a fixnum into the command line it fails the condition test.
if pricex.class.eql? (Fixnum)
then error("wrong type")
else true end
The output does not give me "wrong type"
Any ideas? Thanks
September 27th, 2010, 06:32 AM
My guess is that you are reading a string from the command line and not converting it first. Verify by printing out the actual class type in your function. Something like:
True happiness is not getting what you want, it's wanting what you've already got.
September 27th, 2010, 08:36 PM
Originally Posted by L7Sqr
Thanks, that did the job