Class: Monies::Symbols
- Inherits:
-
Object
- Object
- Monies::Symbols
- Defined in:
- lib/monies/symbols.rb
Instance Method Summary collapse
- #fetch(key) ⇒ Object (also: #[])
- #fetch_key(value) ⇒ Object
-
#initialize ⇒ Symbols
constructor
A new instance of Symbols.
- #keys ⇒ Object
- #store(key, value) ⇒ Object (also: #[]=)
- #update(hash) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ Symbols
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 |
#keys ⇒ Object
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 |
#values ⇒ Object
12 13 14 |
# File 'lib/monies/symbols.rb', line 12 def values @values ||= Regexp.new(@hash.values.map { Regexp.escape(_1) }.join('|')) end |