module OpenString

Public: Provides extension methods for the built-in String class.

Public Instance Methods

palindrome?() click to toggle source

Public: Determines if self has the same sequence of characters as evaluated from index 0 to self.length and from self.length to 0. This ignores whitespace and casing.

Returns true iff self contains the same sequence of characters forwards as it does backwards.

# File lib/open_string.rb, line 11
def palindrome?
  gsub(/\s+/, '').casecmp(reverse.gsub(/\s+/, '')) == 0
end