Ruby's Palindrome Tester


This is a palindrome tester that works on letters and numbers written in ruby. Leave your C++es and Javas at the door, this is a real object-oriented language. Everything is an object. Elegant to a fault. (And here are some palindromes.)

# Loop 'til we're tired of palindromes
while true

	print "Enter the potential palindrome you want to test ('quit' to exit)\n: "
	string = gets.strip		# Get input
	
	if (string <=> "quit") == 0		# Exit?
		exit
	end
	
	# Do test and report result
	if (string.downcase.gsub(/[\s]/, '') <=> string.reverse.downcase.gsub(/[\s]/, '')) == 0
		puts "\"#{string}\" is a palindrome\n\n"
	else
		puts "\"#{string}\" is NOT a palindrome\n\n"
	end
end
palindrome.rb