class String

Overrides Default String Class by adding {palindrome?} method

Public Instance Methods

palindrome?(strict = true) click to toggle source

@param strict [Boolean]

When set to false, will ignore whitespace and string case.

@return [Boolean] Whether or not the string is a palindrome.

# File lib/palindrome_ext/string.rb, line 8
def palindrome?(strict = true)
  str = self
  str = str.downcase.tr("^a-z0-9", "") unless strict
  str == str.reverse
end