Class: Containers::FuzzyHash
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #clear ⇒ Object
- #dup ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(&block) ⇒ FuzzyHash
constructor
A new instance of FuzzyHash.
- #inspect ⇒ Object
- #keys ⇒ Object
- #length ⇒ Object (also: #size)
-
#to_s ⇒ Object
TODO def method_missing(*args, &block) ret = @hash.__send__(*args, &block) rebuild_hash ret end.
- #values ⇒ Object
Constructor Details
#initialize(&block) ⇒ FuzzyHash
Returns a new instance of FuzzyHash.
3 4 5 6 7 8 9 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 3 def initialize(&block) @mapping_proc = block_given? ? block : lambda { |key| [*key] } @auto_array = Containers::AutoassociativeArray.new @hash = {} @values = {} self end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 11 def [](key) mapped_key = @mapping_proc[key] type_assert(mapped_key, Array) match = @auto_array.partial_match(*mapped_key) @values[match[0]] end |
#[]=(key, val) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 18 def []=(key, val) mapped_key = @mapping_proc[key] type_assert(mapped_key, Array) @hash[key] = val @auto_array.insert(*mapped_key) @values[mapped_key] = val end |
#clear ⇒ Object
35 36 37 38 39 40 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 35 def clear @hash.clear @values.clear @auto_array.clear self end |
#dup ⇒ Object
65 66 67 68 69 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 65 def dup ret = self.class.new(&@mapping_proc) @hash.each { |key,val| ret[key] = val } ret end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 26 def empty? @hash.empty? end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 42 def inspect @hash.inspect end |
#keys ⇒ Object
46 47 48 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 46 def keys @hash.keys end |
#length ⇒ Object Also known as: size
30 31 32 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 30 def length @hash.size end |
#to_s ⇒ Object
TODO def method_missing(*args, &block)
ret = @hash.__send__(*args, &block)
rebuild_hash
ret
end
61 62 63 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 61 def to_s @hash.to_s end |
#values ⇒ Object
50 51 52 |
# File 'lib/duct_tape/fuzzy_hash.rb', line 50 def values @hash.values end |