Class: ProstoCache::ProstoHash

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/prosto_cache/prosto_hash.rb

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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