Class: DriveTime::BiDirectionalHash
- Inherits:
-
Object
- Object
- DriveTime::BiDirectionalHash
- Defined in:
- lib/drive_time/bi_directional_hash.rb
Instance Method Summary collapse
- #has_key_for_value(value) ⇒ Object
- #has_value_for_key(key) ⇒ Object
-
#initialize ⇒ BiDirectionalHash
constructor
A new instance of BiDirectionalHash.
- #insert(key, value) ⇒ Object
- #key_for_value(value) ⇒ Object
- #value_for_key(key) ⇒ Object
Constructor Details
#initialize ⇒ BiDirectionalHash
Returns a new instance of BiDirectionalHash.
5 6 7 8 |
# File 'lib/drive_time/bi_directional_hash.rb', line 5 def initialize @key_to_value = {} @value_to_key = {} end |
Instance Method Details
#has_key_for_value(value) ⇒ Object
23 24 25 |
# File 'lib/drive_time/bi_directional_hash.rb', line 23 def has_key_for_value(value) return !key_for_value(value).nil? end |
#has_value_for_key(key) ⇒ Object
27 28 29 |
# File 'lib/drive_time/bi_directional_hash.rb', line 27 def has_value_for_key(key) return !value_for_key(key).nil? end |
#insert(key, value) ⇒ Object
10 11 12 13 |
# File 'lib/drive_time/bi_directional_hash.rb', line 10 def insert(key, value) @key_to_value[key] = value; @value_to_key[value] = key; end |
#key_for_value(value) ⇒ Object
19 20 21 |
# File 'lib/drive_time/bi_directional_hash.rb', line 19 def key_for_value(value) return @value_to_key[value] end |
#value_for_key(key) ⇒ Object
15 16 17 |
# File 'lib/drive_time/bi_directional_hash.rb', line 15 def value_for_key(key) return @key_to_value[key] end |