Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created January 17, 2014 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakenickels/8468899 to your computer and use it in GitHub Desktop.
Save fakenickels/8468899 to your computer and use it in GitHub Desktop.
Frequently used words scanner in Ruby
module Analiser
extend self
def parse(text)
originalArray = text.split(/\s/).reject {|x| x.empty?}
repeatedWords = {}
originalArray.each do |word|
word.downcase!
if repeatedWords.has_key?(word.to_sym)
repeatedWords[word.to_sym] += 1
else
repeatedWords[word.to_sym] = 1
end
end
repeatedWords
end
end
# Analiser.parse('hello word word hello')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment