Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/redisarray/core_ext/hash/reverse_merge.rb,
lib/redisarray/core_ext/array/extract_options.rb
Instance Method Summary collapse
-
#extractable_options? ⇒ Boolean
By default, only instances of Hash itself are extractable.
-
#reverse_merge(other_hash) ⇒ Object
Merges the caller into
other_hash
. -
#reverse_merge!(other_hash) ⇒ Object
(also: #reverse_update)
Destructive
reverse_merge
.
Instance Method Details
#extractable_options? ⇒ Boolean
By default, only instances of Hash itself are extractable. Subclasses of Hash may implement this method and return true to declare themselves as extractable. If a Hash is extractable, Array#extract_options! pops it from the Array when it is the last element of the Array.
7 8 9 |
# File 'lib/redisarray/core_ext/array/extract_options.rb', line 7 def instance_of?(Hash) end |
#reverse_merge(other_hash) ⇒ Object
Merges the caller into other_hash
. For example,
= .reverse_merge(:size => 25, :velocity => 10)
is equivalent to
= {:size => 25, :velocity => 10}.merge()
This is particularly useful for initializing an options hash with default values.
12 13 14 |
# File 'lib/redisarray/core_ext/hash/reverse_merge.rb', line 12 def reverse_merge(other_hash) other_hash.merge(self) end |
#reverse_merge!(other_hash) ⇒ Object Also known as: reverse_update
Destructive reverse_merge
.
17 18 19 20 |
# File 'lib/redisarray/core_ext/hash/reverse_merge.rb', line 17 def reverse_merge!(other_hash) # right wins if there is no left merge!(other_hash) { |key, left, right| left } end |