Sha256: f88dcdbefe4deab425ccf93bb44708d23bc91059688fc33984fbd0936765eafa
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require_relative "tmart134_palindrome/version" module Tmart134Palindrome #Returns true for a palindrome, false otherwise def palindrome? if processed_content.empty? false else processed_content == processed_content.reverse end end private #Returns content downcased for palindrome testing def processed_content #self.letters.downcase to_s.scan(/[a-z0-9]/i).join.downcase end end class String include Tmart134Palindrome end class Integer include Tmart134Palindrome end # class String # #Returns true for a palindrome, false otherwise # def palindrome? # processed_content == processed_content.reverse # end # #Returns the letters in a string # def letters # the_letters =[] # #letter_regex = /[a-z]/i # self.chars.select { |c| c.match(/[a-z]/i) }.join # # self.chars.each do |character| # # if character.match(letter_regex) # # the_letters << character # # end # # end # # for i in 0..self.length-1 # # character = self[i] # # if (character.match(letter_regex)) # # the_letters << character # # end # # end # #the_letters.join # end # private # #Returns content downcased for palindrome testing # def processed_content # #self.letters.downcase # scan(/[a-z]/i).join.downcase # end # end # module Tmart134Palindrome # class Error < StandardError; end # # Your code goes here... # end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tmart134_palindrome-0.2.1 | lib/tmart134_palindrome.rb |