Skip to content

Instantly share code, notes, and snippets.

@Papillard
Last active December 19, 2015 21:29
Show Gist options
  • Save Papillard/6020813 to your computer and use it in GitHub Desktop.
Save Papillard/6020813 to your computer and use it in GitHub Desktop.
Extending palindrome? on String & Enumerable
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