Class: Eluka::Bijection
- Inherits:
-
Hash
- Object
- Hash
- Eluka::Bijection
- Defined in:
- lib/eluka/bijection.rb
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
-
#initialize(*args) ⇒ Bijection
constructor
A new instance of Bijection.
- #lookup(val) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Bijection
Returns a new instance of Bijection.
6 7 8 9 |
# File 'lib/eluka/bijection.rb', line 6 def initialize(*args) super(*args) @reverse = self.invert end |
Instance Method Details
#[]=(key, val) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/eluka/bijection.rb', line 11 def []=(key, val) super(key, val) if @reverse.has_key?(val) self.delete(@reverse[val]) end @reverse[val] = key end |
#lookup(val) ⇒ Object
19 20 21 |
# File 'lib/eluka/bijection.rb', line 19 def lookup(val) @reverse[val] end |