betoesquivel

correct palindrome

May 18th, 2015
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.38 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # -*- ruby -*-
  3.  
  4. def palindrome?(sentence='')
  5.   return false if !sentence.is_a? String
  6.   palindrome = sentence.delete(' ').downcase
  7.   return !palindrome.empty? && palindrome == palindrome.reverse
  8. end
  9.  
  10. sentence = gets.chomp
  11. if (palindrome?(sentence))
  12.   puts "#{sentence} is a palindrome"
  13. else
  14.   puts "#{sentence} is not a palindrome"
  15. end
  16.  
  17. palindrome?
Advertisement
Add Comment
Please, Sign In to add comment