Class: Monies::Symbols

Inherits:
Object
  • Object
show all
Defined in:
lib/monies/symbols.rb

Instance Method Summary collapse

Constructor Details

#initializeSymbols

Returns a new instance of Symbols.



4
5
6
# File 'lib/monies/symbols.rb', line 4

def initialize
  @hash, @inverse_hash = Hash.new, Hash.new
end

Instance Method Details

#fetch(key) ⇒ Object Also known as: []



16
17
18
# File 'lib/monies/symbols.rb', line 16

def fetch(key)
  @hash.fetch(key)
end

#fetch_key(value) ⇒ Object



21
22
23
# File 'lib/monies/symbols.rb', line 21

def fetch_key(value)
  @inverse_hash.fetch(value)
end

#keysObject



8
9
10
# File 'lib/monies/symbols.rb', line 8

def keys
  @keys ||= Regexp.new(@hash.keys.map { Regexp.escape(_1) }.join('|'))
end

#store(key, value) ⇒ Object Also known as: []=



25
26
27
28
29
30
31
32
33
# File 'lib/monies/symbols.rb', line 25

def store(key, value)
  @hash[key] = value

  @inverse_hash[value] = key

  @keys, @values = nil

  value
end

#update(hash) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/monies/symbols.rb', line 36

def update(hash)
  @hash.update(hash)

  @inverse_hash = @hash.invert

  @keys, @values = nil

  self
end

#valuesObject



12
13
14
# File 'lib/monies/symbols.rb', line 12

def values
  @values ||= Regexp.new(@hash.values.map { Regexp.escape(_1) }.join('|'))
end