From: Robert Klemme Date: 2007-11-23T03:30:00+09:00 Subject: Re: Checking whether a string is a number in disguise? 2007/11/22, Peter Bunyan : > I'm working on an RPN calculator (don't ask why...) and I'm having > trouble getting a number from gets - how am I supposed to know whether > it's a number? > > At the moment I'm doing [eval(oper) == oper.to_f], which is far from > ideal. Any ideas? You all get to win my calculator if you know of a > better way :D. str = gets # chomp is not needed for Float num = Float(str) rescue nil if num puts "I'm a number: #{num}" end Cheers robert -- use.inject do |as, often| as.you_can - without end