lib/juandpineiro_palindrome.rb in juandpineiro_palindrome-0.1.0 vs lib/juandpineiro_palindrome.rb in juandpineiro_palindrome-0.2.0
- old
+ new
@@ -1,15 +1,27 @@
require "juandpineiro_palindrome/version"
-class String
+module JuandpineiroPalindrome
# Returns true for a palindrome, false otherwise.
def palindrome?
- processed_content == processed_content.reverse
+ if processed_content.empty?
+ false
+ else
+ processed_content == processed_content.reverse
+ end
end
private
# Returns content for palindrome testing.
def processed_content
- scan(/[a-z]/i).join.downcase
+ to_s.scan(/[a-z\d]/i).join.downcase
end
+end
+
+class String
+ include JuandpineiroPalindrome
+end
+
+class Integer
+ include JuandpineiroPalindrome
end