Class: Randexp::Dictionary

### Home Classes Methods

### In Files

- lib/randexp/dictionary.rb

### Parent

Object

### Methods

- ::load_dictionary
- ::words
- ::words_by_length

### Files

- LICENSE
- README
- TODO

### Class/Module Index

Quicksearch

- Randexp
- Randexp::Dictionary
- Randexp::Parser
- Randexp::Reducer
- Array
- Integer
- Randgen
- Range
- RealName
- Regexp

No matching classes.

# Randexp::Dictionary

### Public Class Methods

load_dictionary() click to toggle source

    # File lib/randexp/dictionary.rb, line 2
    def self.load_dictionary
      if File.exists?("/usr/share/dict/words")
        File.read("/usr/share/dict/words").split
      elsif File.exists?("/usr/dict/words")
        File.read("/usr/dict/words").split
      else
        raise "Words file not found. Check if it is installed in (/usr/share/dict/words or /usr/dict/words) "
      end
    end

words(options = {}) click to toggle source

    # File lib/randexp/dictionary.rb, line 12
    def self.words(options = {})
      if options.has_key?(:length)
        words_by_length[options[:length]]
      else
        @@words ||= load_dictionary
      end
    end

words_by_length() click to toggle source

    # File lib/randexp/dictionary.rb, line 20
    def self.words_by_length
      @@words_by_length ||= begin
        hash = Hash.new {|h,k| h[k] = [] }
        words.inject(hash) {|h, w| h[w.size] << w; h }
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.