Class: ProstoCache::ProstoHash
- Inherits:
-
Object
- Object
- ProstoCache::ProstoHash
- Extended by:
- Forwardable
- Defined in:
- lib/prosto_cache/prosto_hash.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(hash = {}) ⇒ ProstoHash
constructor
A new instance of ProstoHash.
- #keys(init = nil) ⇒ Object
- #values(init = nil) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ ProstoHash
Returns a new instance of ProstoHash.
4 5 6 |
# File 'lib/prosto_cache/prosto_hash.rb', line 4 def initialize(hash = {}) @hash = hash.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v } end |
Instance Method Details
#[](key) ⇒ Object
8 9 10 11 |
# File 'lib/prosto_cache/prosto_hash.rb', line 8 def [](key) raise ArgumentError unless key hash[key.to_sym] end |
#[]=(key, value) ⇒ Object
13 14 15 16 |
# File 'lib/prosto_cache/prosto_hash.rb', line 13 def []=(key, value) raise ArgumentError unless key hash[key.to_sym] = value end |
#keys(init = nil) ⇒ Object
18 19 20 |
# File 'lib/prosto_cache/prosto_hash.rb', line 18 def keys(init = nil) @keys = @keys || init || hash.keys end |
#values(init = nil) ⇒ Object
22 23 24 |
# File 'lib/prosto_cache/prosto_hash.rb', line 22 def values(init = nil) @values = @values || init || hash.values end |