Module: ReservedWord

Defined in:
lib/reserved_word.rb,
lib/reserved_word/word.rb,
lib/reserved_word/version.rb

Defined Under Namespace

Modules: Word

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.allObject



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

def self.all
  @words.to_hash
end

.clearObject



17
18
19
# File 'lib/reserved_word.rb', line 17

def self.clear
  @words.default_words = Array.new
end

.clear_allObject



21
22
23
24
# File 'lib/reserved_word.rb', line 21

def self.clear_all
  @words = ActiveSupport::OrderedOptions.new
  self.clear
end

.include?(word) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/reserved_word.rb', line 9

def self.include?(word)
  @words.default_words.include?(word)
end

.listObject



13
14
15
# File 'lib/reserved_word.rb', line 13

def self.list
  @words.default_words
end

.load!(type, key = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/reserved_word.rb', line 34

def self.load!(type, key=nil)
  if key == nil
    @words.default_words = load_words(type)
  else
    @words[key] = load_words(type)
  end
end

.load_words(type) ⇒ Object



42
43
44
# File 'lib/reserved_word.rb', line 42

def self.load_words(type)
  ReservedWord::Word.const_get(type.upcase)
end

.method_missing(sym, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/reserved_word.rb', line 46

def self.method_missing(sym, *args, &block)
  sym = $1.to_sym if sym.to_s =~ /(.*)=$/
  super if ReservedWord.singleton_methods.include? sym

  if @words[sym] == nil
    if args.first.class == Array
      @words[sym] = args.first
    else
      super
    end
  else
    @words[sym]
  end
end

.word_listObject



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

def self.word_list
  ReservedWord::Word.constants.map(&:downcase)
end