class HashMap
Public Class Methods
new(&key_generator_prc)
click to toggle source
# File lib/hash_map.rb, line 2 def initialize(&key_generator_prc) key_generator_prc ||= Proc.new { |val| val.hash } @cache = {} @key_generator_prc = key_generator_prc end
Public Instance Methods
[](key)
click to toggle source
# File lib/hash_map.rb, line 31 def [](key) @cache[key] end
add(val)
click to toggle source
# File lib/hash_map.rb, line 12 def add(val) key = create_key(val) @cache[key] = val end
create_key(val)
click to toggle source
# File lib/hash_map.rb, line 8 def create_key(val) @key_generator_prc.call(val) end
each() { |key, value| ... }
click to toggle source
# File lib/hash_map.rb, line 39 def each @cache.each { |key, value| yield key, value } end
include?(val)
click to toggle source
# File lib/hash_map.rb, line 26 def include?(val) key = create_key(val) @cache.include?(key) end
length()
click to toggle source
# File lib/hash_map.rb, line 35 def length @cache.length end
remove(val)
click to toggle source
# File lib/hash_map.rb, line 17 def remove(val) key = create_key(val) @cache.delete(key) end
update(val)
click to toggle source
# File lib/hash_map.rb, line 22 def update(val) add(val) end