Palindrome in programming — Ruby

Junaid Abbasi
2 min readNov 29, 2020
©Paramount Pictures

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.

A scene of movie Arrival

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

--

--

Junaid Abbasi
Junaid Abbasi

Written by Junaid Abbasi

Small business | Personal Development | Programming 👾

No responses yet