Class: Oulipo::WordList

Inherits:
Object
  • Object
show all
Defined in:
lib/oulipo/word_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWordList

Returns a new instance of WordList.



3
4
5
# File 'lib/oulipo/word_list.rb', line 3

def initialize
  @words = []
end

Class Method Details

.load(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/oulipo/word_list.rb', line 7

def self.load(file)
  dict = self.new
  file = File.open(file) if file.is_a?(String)
  
  file.each_line do |word|
    dict.push(word.strip)
  end
  
  dict
end

Instance Method Details

#[](index) ⇒ Object



26
27
28
# File 'lib/oulipo/word_list.rb', line 26

def [](index)
  @words[index]
end

#index(word) ⇒ Object



18
19
20
# File 'lib/oulipo/word_list.rb', line 18

def index(word)
  @words.index(word)
end

#lengthObject



22
23
24
# File 'lib/oulipo/word_list.rb', line 22

def length
  @words.length
end

#push(word) ⇒ Object



30
31
32
# File 'lib/oulipo/word_list.rb', line 30

def push(word)
  @words.push(word)
end