Skip to content

Instantly share code, notes, and snippets.

@jmoon90
Created December 10, 2013 14:04
Show Gist options
  • Select an option

  • Save jmoon90/7891047 to your computer and use it in GitHub Desktop.

Select an option

Save jmoon90/7891047 to your computer and use it in GitHub Desktop.
class WordCount
def initialize(sentence)
@sentence = sentence
end
def frequency
word_counter = Hash.new(0)
@sentence.split(' ').each do |word|
word_counter[word.downcase] += 1
end
word_counter
end
end
require_relative "word_count"
require "rspec"
describe WordCount do
require 'pry'
it "count the frequency of each word" do
expect(WordCount.new('Toy boat toy boat toy boat').frequency).to eql( { 'toy' => 3, 'boat' => 3 } )
end
it 'ignores non word or number characteristics'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment