lib/groupie/group.rb in groupie-0.3.0 vs lib/groupie/group.rb in groupie-0.4.0

- old
+ new

@@ -1,8 +1,12 @@ +# frozen_string_literal: true + class Groupie + # Group represents a group or category that words can be classified into. class Group attr_reader :word_counts + def initialize(name) @name = name @word_counts = {} end @@ -15,20 +19,22 @@ words.flatten.each do |word| add_word(word) end nil end + alias << add # Return the count for a specific +word+. def count(word) @word_counts[word] || 0 end + private + # Add a single word and count it. def add_word(word) @word_counts[word] ||= 0 @word_counts[word] += 1 end - private :add_word end -end \ No newline at end of file +end