Class: CodeRay::CaseIgnoringWordList
- Defined in:
- 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.
Instance Method Summary collapse
-
#add(words, kind = true) ⇒ Object
Add
words
to the list and associate them withkind
. -
#initialize(default = false, caching = false) ⇒ CaseIgnoringWordList
constructor
Creates a new case-insensitive WordList with
default
as default value.
Constructor Details
#initialize(default = false, caching = false) ⇒ CaseIgnoringWordList
Creates a new case-insensitive WordList with default
as default value.
You can activate caching to store the results for every [] request.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/coderay/helpers/word_list.rb', line 101 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) def self.[] key # :nodoc: super(key.downcase) end end end |
Instance Method Details
#add(words, kind = true) ⇒ Object
Add words
to the list and associate them with kind
.
115 116 117 118 119 120 |
# File 'lib/coderay/helpers/word_list.rb', line 115 def add words, kind = true words.each do |word| self[word.downcase] = kind end self end |