Sha256: 3607587eeed0998e1ed3c9411b99e692db55b30b0653ce8b575611274393e460

Contents?: true

Size: 605 Bytes

Versions: 1

Compression:

Stored size: 605 Bytes

Contents

class Groupie
  class Group
    attr_reader :word_counts
    def initialize(name)
      @name = name
      @word_counts = {}
    end

    def words
      @word_counts.keys
    end

    # Add new words to the group.
    def add(*words)
      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

    # 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groupie-0.3.0 lib/groupie/group.rb