Class: Recliner::Map
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
Assigns a new value to the map:.
-
#fetch(key, *args, &block) ⇒ Object
Fetches the value for the specified key, same as doing hash.
-
#key?(key) ⇒ Boolean
(also: #include?, #has_key?, #member?)
Checks the map for a key matching the argument passed in:.
- #replace(hash) ⇒ Object
- #store(key, value) ⇒ Object
-
#update(hash) ⇒ Object
Updates the instantized map with values from the second:.
Class Method Details
.[](hash) ⇒ Object
82 83 84 85 86 |
# File 'lib/recliner/properties/map.rb', line 82 def self.[](hash) result = new result.update(hash) result end |
.from_couch(hash) ⇒ Object
67 68 69 70 71 |
# File 'lib/recliner/properties/map.rb', line 67 def from_couch(hash) result = new hash.each_pair { |key, value| result[from.from_couch(key)] = to.from_couch(value) } result end |
Instance Method Details
#[](key) ⇒ Object
88 89 90 |
# File 'lib/recliner/properties/map.rb', line 88 def [](key) super(convert_key(key)) end |
#[]=(key, value) ⇒ Object
Assigns a new value to the map:
map[:key] = "value"
101 102 103 |
# File 'lib/recliner/properties/map.rb', line 101 def []=(key, value) super(convert_key(key), convert_value(value)) end |
#fetch(key, *args, &block) ⇒ Object
Fetches the value for the specified key, same as doing hash
93 94 95 |
# File 'lib/recliner/properties/map.rb', line 93 def fetch(key, *args, &block) super(convert_key(key), *args, &block) end |
#key?(key) ⇒ Boolean Also known as: include?, has_key?, member?
Checks the map for a key matching the argument passed in:
map["key"] = "value"
map.key? :key # => true
map.key? "key" # => true
130 131 132 |
# File 'lib/recliner/properties/map.rb', line 130 def key?(key) super(convert_key(key)) end |
#replace(hash) ⇒ Object
138 139 140 141 |
# File 'lib/recliner/properties/map.rb', line 138 def replace(hash) clear update(hash) end |
#store(key, value) ⇒ Object
105 106 107 |
# File 'lib/recliner/properties/map.rb', line 105 def store(key, value) super(convert_key(key), convert_value(value)) end |
#update(hash) ⇒ Object
119 120 121 122 |
# File 'lib/recliner/properties/map.rb', line 119 def update(hash) hash.each_pair { |key, value| self[key] = value } self end |