Parent

Randexp::Dictionary

Public Class Methods

load_dictionary() click to toggle source
    # File lib/randexp/dictionary.rb, line 2
 2:   def self.load_dictionary
 3:     if File.exists?("/usr/share/dict/words")
 4:       File.read("/usr/share/dict/words").split
 5:     elsif File.exists?("/usr/dict/words")
 6:       File.read("/usr/dict/words").split
 7:     else
 8:       raise "Words file not found. Check if it is installed in (/usr/share/dict/words or /usr/dict/words) "
 9:     end
10:   end
words(options = {}) click to toggle source
    # File lib/randexp/dictionary.rb, line 12
12:   def self.words(options = {})
13:     if options.has_key?(:length)
14:       words_by_length[options[:length]]
15:     else
16:       @@words ||= load_dictionary
17:     end
18:   end
words_by_length() click to toggle source
    # File lib/randexp/dictionary.rb, line 20
20:   def self.words_by_length
21:     @@words_by_length ||= begin
22:       hash = Hash.new {|h,k| h[k] = [] }
23:       words.inject(hash) {|h, w| h[w.size] << w; h }
24:     end
25:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.