Class: Wordlist::Words

Inherits:
AbstractWordlist show all
Defined in:
lib/wordlist/words.rb

Overview

An in-memory wordlist of words.

Wordlist::Words["foo", "bar", "baz"]

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ListMethods

#capitalize, #concat, #downcase, #gsub, #intersect, #mutate, #mutate_case, #power, #product, #sub, #subtract, #tr, #union, #uniq, #upcase

Constructor Details

#initialize(words = []) ⇒ Words

Creates a new wordlist object.

Parameters:

  • words (Array<String>, Enumerable) (defaults to: [])

    The words for the wordlist.

Since:

  • 1.0.0



29
30
31
# File 'lib/wordlist/words.rb', line 29

def initialize(words=[])
  @words = words
end

Instance Attribute Details

#wordsArray<String>, Enumerable (readonly)

The words in the wordlist.

Returns:

  • (Array<String>, Enumerable)

Since:

  • 1.0.0



19
20
21
# File 'lib/wordlist/words.rb', line 19

def words
  @words
end

Class Method Details

.[](*words) ⇒ Object

Creates a new wordlist from the given words.

Examples:

Wordlist::Words["foo", "bar", "baz"]

Parameters:

  • words (Array<String>)

    The words for the wordlist.

Since:

  • 1.0.0



44
45
46
# File 'lib/wordlist/words.rb', line 44

def self.[](*words)
  new(words)
end

Instance Method Details

#each {|word| ... } ⇒ Enumerator

Enumerate through every word in the in-memory wordlist.

Examples:

words.each do |word|
  puts word
end

Yields:

  • (word)

    The given block will be passed each word in the list.

Yield Parameters:

  • word (String)

    A word from the in-memory wordlist.

Returns:

  • (Enumerator)

    If no block is given, then an Enumerator object will be returned.

Since:

  • 1.0.0



67
68
69
# File 'lib/wordlist/words.rb', line 67

def each(&block)
  @words.each(&block)
end