O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#8 Palindromes (palindrome.rb and palindrome2.rb)

I’m rounding out this chapter with a few shorter examples pertaining to palindromes, which are bits of text that are the same when reversed as they are when read normally. Usually, we allow cheating to ignore spaces, capitalization differences, and punctuation, so A man, a plan, a canal, Panama qualifies as a palindrome under those conditions. While working on this book, I was reading another programming book that contained a discussion about palindromes. “Great!” I thought. “I’ll add a palindrome? predicate method to all Strings. It’ll be a nice simple bit to have in the chapter in which I talk about text.” So I started thinking about breaking Strings into individual characters, writing a method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required