Sha256: 1f6eb6afc31983a33933c5c533378d2eb6dd3bdc9f05f9e46014e3b4780c8b45

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true
require "wordlist/abstract_wordlist"

module Wordlist
  #
  # An in-memory wordlist of words.
  #
  #     Wordlist::Words["foo", "bar", "baz"]
  #
  # @api public
  #
  # @since 1.0.0
  #
  class Words < AbstractWordlist

    # The words in the wordlist.
    #
    # @return [Array<String>, Enumerable]
    attr_reader :words

    #
    # Creates a new wordlist object.
    #
    # @param [Array<String>, Enumerable] words
    #   The words for the wordlist.
    #
    # @api public
    #
    def initialize(words=[])
      @words = words
    end

    #
    # Creates a new wordlist from the given words.
    #
    # @param [Array<String>] words
    #   The words for the wordlist.
    #
    # @example
    #   Wordlist::Words["foo", "bar", "baz"]
    #
    # @api public
    #
    def self.[](*words)
      new(words)
    end

    #
    # Enumerate through every word in the in-memory wordlist.
    #
    # @yield [word]
    #   The given block will be passed each word in the list.
    #
    # @yieldparam [String] word
    #   A word from the in-memory wordlist.
    #
    # @return [Enumerator]
    #   If no block is given, then an `Enumerator` object will be returned.
    #
    # @example
    #   words.each do |word|
    #     puts word
    #   end
    #
    # @api public
    #
    def each(&block)
      @words.each(&block)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wordlist-1.1.1 lib/wordlist/words.rb
wordlist-1.1.0 lib/wordlist/words.rb
wordlist-1.0.3 lib/wordlist/words.rb
wordlist-1.0.2 lib/wordlist/words.rb
wordlist-1.0.1 lib/wordlist/words.rb