Class: CodeRay::CaseIgnoringWordList

Inherits:
WordList show all
Defined in:
vendor/plugins/coderay-0.9.2/lib/coderay/helpers/word_list.rb

Overview

A CaseIgnoringWordList is like a WordList, only that keys are compared case-insensitively.

Ignoring the text case is realized by sending the downcase message to all keys.

Caching usually makes a CaseIgnoringWordList faster, but it has to be activated explicitely.

Defined Under Namespace

Modules: Uncached

Instance Method Summary

Methods inherited from Hash

#except, #except!

Constructor Details

- (CaseIgnoringWordList) initialize(default = false, caching = false)

Creates a new case-insensitive WordList with default as default value.

You can activate caching to store the results for every [] request. This speeds up subsequent lookups for the same word, but also uses memory.



103
104
105
106
107
108
109
110
111
112
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/word_list.rb', line 103

def initialize default = false, caching = false
  if caching
    super(default, false) do |h, k|
      h[k] = h.fetch k.downcase, default
    end
  else
    super(default, false)
    extend Uncached
  end
end

Instance Method Details

- (Object) add(words, kind = true)

Add words to the list and associate them with kind.



121
122
123
124
125
126
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/word_list.rb', line 121

def add words, kind = true
  words.each do |word|
    self[word.downcase] = kind
  end
  self
end