Class: Eluka::Bijection

Inherits:
Hash
  • Object
show all
Defined in:
lib/eluka/bijection.rb

Instance Method Summary collapse

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