Palindrome in programming — Ruby
Palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam, racecar.
I watched an amazing movie “Arrival”. In the movie twelve extraterrestrial spacecraft silently hover over disparate locations around the Earth.
One of the character Louise Banks’s daughter Hannah. Asks her mother that why she was named ‘Hannah’. Louise replies that her name is very special as it is a palindrome; it reads the same forward and backward.
I decided to develop a simple method in Ruby to check if a name/word is palindrome or not.
Let’s do the programming!!
We’ll write a boolean method named palindrome?
which will take name/word as an argument returns true
if it’s palindrome and false
if it’s not
def palindrome?(word)
word.reverse == word ? "#{word} is a palindrome word" : "#{word} is not a palindrome word"
end
Let’s break it down
def palindrome?(word)
defines a method named palindrome? and takes word as an argument