class Dictionary

Class to model Dictionary

Attributes

filename[R]

Public Class Methods

new(filename) click to toggle source
# File lib/dictionary.rb, line 7
def initialize(filename)
  @filename = filename
end

Public Instance Methods

word() click to toggle source
# File lib/dictionary.rb, line 11
def word
  @word ||= words.sample.downcase
end

Private Instance Methods

words() click to toggle source
# File lib/dictionary.rb, line 17
def words
  @words ||= File.open(File.join(File.dirname(__FILE__), "../static/#{filename}")) do |f|
    f.readlines(chomp: true)
     .reject { |word| word.size < 5 || word.size > 12 }
  end
end