Skip to content

Instantly share code, notes, and snippets.

@blake41
Created July 29, 2015 16:07
Show Gist options
  • Save blake41/3eb70b6bd4ef16b8bce7 to your computer and use it in GitHub Desktop.
Save blake41/3eb70b6bd4ef16b8bce7 to your computer and use it in GitHub Desktop.
sentence = <<-something
Steven likes the movies. Blake likes to ride his bike but hates movies.
Blake is taller than steven. Steven is a great teacher.
something
sentence = sentence.gsub("."," ") # you can chain more then one gsub
sentence = sentence.split(" ").collect {|word| word.capitalize}
cont = {}
sentence.each do |filler|
cont[filler] = 0
end
cont.each_pair do |word,number_of_occ|
sentence.each do |anotherword|
if word == anotherword
cont[word] = cont[word] + 1
end
end
end
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment