Skip to content

Instantly share code, notes, and snippets.

@s-osa
Created April 1, 2014 14:27
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 s-osa/9915236 to your computer and use it in GitHub Desktop.
Save s-osa/9915236 to your computer and use it in GitHub Desktop.
def count_by_word(string)
hash = Hash.new(0)
string.split(' ').each{|word| hash[word] += 1}
hash
end
describe "count by word" do
it "counts by word" do
expect(count_by_word("no ruby no life")).to eq("no" => 2, "life" => 1, "ruby" => 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment