Module: DandradePalindrome

Included in:
Integer, String
Defined in:
lib/dandrade_palindrome.rb,
lib/dandrade_palindrome/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#lettersObject

Returns the letters in the strring.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dandrade_palindrome.rb', line 16

def letters
  # the_letters = []
  letter_regex = /[a-z]/i
  # for i in 0..self.length - 1
  #   character = self[i]
  #   if (character.match(letter_regex))
  #     the_letters << character
  #   end
  # end

  # self.chars.each do |character|
  #   if character.match(letter_regex)
  #     the_letters << character
  #   end
  # end
  # the_letters.join

  # self.chars.select { |c| c.match letter_regex }.join

  # self.chars.map{ |c| c.match /[a-zA-Z]/ }.join

  self.scan(letter_regex).join
end

#palindrome?Boolean

Returns true for a palindrome, false otherwise.



7
8
9
10
11
12
13
# File 'lib/dandrade_palindrome.rb', line 7

def palindrome?
  if processed_content.empty?
    false
  else
    processed_content == processed_content.reverse
  end
end