Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/palindrome_ext/string.rb

Overview

Overrides Default String Class by adding #palindrome? method

Instance Method Summary collapse

Instance Method Details

#palindrome?(strict = true) ⇒ Boolean

Returns Whether or not the string is a palindrome.

Parameters:

  • strict (Boolean) (defaults to: true)

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

Returns:

  • (Boolean)

    Whether or not the string is a palindrome.



8
9
10
11
12
# 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