class RichHash
Hash impersonator that accepts regular expressions as keys. But the regular expression lookups are slow, so don't use them (unless you have to).
Public Class Methods
new()
click to toggle source
# File lib/boyermoore.rb, line 6 def initialize @regexps = {} @regular = {} end
Public Instance Methods
[](k)
click to toggle source
# File lib/boyermoore.rb, line 11 def [](k) regular = @regular[k] return regular if regular if @regexps.size > 0 @regexps.each do |regex,v| # linear search is going to be slow return v if regex.match(k) end end nil end
[]=(k,v)
click to toggle source
# File lib/boyermoore.rb, line 22 def []=(k,v) if k.kind_of?(Regexp) @regexps[k] = v else @regular[k] = v end end