Last active
December 19, 2015 21:29
-
-
Save Papillard/6020813 to your computer and use it in GitHub Desktop.
Extending palindrome? on String & Enumerable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def method_missing( method, *args, &block ) | |
method.to_s == "palindrome?" ? self.gsub(/\W/,"").downcase.reverse == self.gsub(/\W/,"").downcase : super | |
end | |
end | |
module Enumerable | |
def method_missing( method, *args, &block ) | |
method.to_s == "palindrome?" ? self.to_a.reverse == self.to_a : super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment