class RandomWords::Generator

def from_file(filename)

Returns:
  • (Array) - An array of words loaded from the file

Parameters:
  • filename (String) -- The name of the file to load
def from_file(filename)
  filename = "#{filename.sub(/\.txt$/, '')}.txt"
  path = File.join(__dir__, 'words', @source.to_s, filename)
  path = File.join(__dir__, 'words', 'english', filename) unless File.exist?(path)
  File.read(path).split("\n").map(&:strip) # Changed from split_lines to split("\n")
rescue Errno::ENOENT
  warn "File not found: #{filename}"
  []
end