Skip to content

Instantly share code, notes, and snippets.

@Papillard
Last active December 19, 2015 06:19
Show Gist options
  • Save Papillard/5910865 to your computer and use it in GitHub Desktop.
Save Papillard/5910865 to your computer and use it in GitHub Desktop.
nice little functions to get familiar with string & regexp..
def palindrome? string
string.gsub(/\W/,"").downcase.reverse == string.gsub(/\W/,"").downcase
end
def count_words string
result = {}
string.downcase.split(/\W+/).each do |word|
result[word] = result[word] ? result[word] + 1 : 1
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment