Skip to content

Instantly share code, notes, and snippets.

@scrogson
Created March 30, 2009 08:39
Show Gist options
  • Save scrogson/87688 to your computer and use it in GitHub Desktop.
Save scrogson/87688 to your computer and use it in GitHub Desktop.
Add a palidrome? method to the Ruby String ojbect. Completely pointless.
class String
def palindrome?
self.gsub!(/[[:punct:][:space:]]/, '')
self.downcase == self.downcase.reverse
end
end
require File.join(File.dirname(__FILE__), '../palindrome')
describe String do
it "should have a palindrome? method" do
"String".should respond_to :palindrome?
end
it "should acknowledge a valid palindrome" do
valid_palindromes = [
"Madam, I'm Adam.",
"Do geese see God?",
"Was it Eliot's toilet I saw?",
"Murder for a jar of red rum."
]
valid_palindromes.each do |p|
p.palindrome?.should be_true
end
end
it "should reject non-valid palindromes" do
"blah blah blah".palindrome?.should be_false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment