class Array
Overrides Default Array
Class by adding {palindrome?} method.
Public Instance Methods
palindrome?(strict = true)
click to toggle source
@param strict whether or not to ignore whitespace and non-alphanumeric characters. @return [Boolean] Whether or not the array is a palindrome.
# File lib/palindrome_ext/array.rb, line 9 def palindrome?(strict = true) return self == reverse if strict arr = map { |x| x.to_s.downcase.tr("^a-z0-9", "") } arr.delete_if(&:empty?) arr == arr.reverse end