From: 7stud -- Date: 2007-11-02T14:05:19+09:00 Subject: Re: Can't get my regexp to work to test if numerical Feng Tien wrote: > alright, this seems easy enough. > > Building a Bank class, deposits must be floating, so if it has any > letters, it will tell the user it needs numbers > > > if amount == /^[0-9]$/ > deposit_to_acct(amount,current_account) > puts 'You have deposited ' + amount.to_s > > else > puts 'Must be a number, alphabet bank is next door to your > right' > > end 1) The pattern /^[0-9]$/ matches one digit. 2) amount would have to be a regex object to == the regex on the right. if 'abc' == /abc/ puts 'yes' else puts 'no' end regex_obj = /abc/ if regex_obj == /abc/ puts 'yes' else puts 'no' end --output:-- no yes -- Posted via http://www.ruby-forum.com/.