lib/HumbleCarrot_palindrome.rb in HumbleCarrot_palindrome-0.1.0 vs lib/HumbleCarrot_palindrome.rb in HumbleCarrot_palindrome-0.1.1
- old
+ new
@@ -1,15 +1,28 @@
require "HumbleCarrot_palindrome/version"
-class String
+module HumbleCarrotPalindrome
# 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.
- private def processed_content
- self.scan(/[a-z]/i).join.downcase
- end
+ # Returns content for palindrome testing.
+ def processed_content
+ self.to_s.scan(/[a-z|0-9]/i).join.downcase
+ end
+end
+
+class String
+ include HumbleCarrotPalindrome
+end
+
+class Integer
+ include HumbleCarrotPalindrome
end
\ No newline at end of file