Class: Hash
- Defined in:
- lib/reactive_support/core_ext/object/blank.rb,
lib/reactive_support/core_ext/object/deep_dup.rb
Overview
Instance Method Summary collapse
-
#deep_dup ⇒ Object
When called on a hash, the
#deep_dupmethod duplicates all the key-value pairs in the hash recursively, so that actions on the duplicate do not affect the original hash:. -
#present? ⇒ Boolean
When called on a hash (or any enumerable), the
#present?method returnstrueif the hash is not empty, even if its elements have blank values: { foo: :bar }.present? # => true { ‘bar’ => nil }.present? # => true {}.present? # => false.
Instance Method Details
#deep_dup ⇒ Object
When called on a hash, the #deep_dup method duplicates all the key-value pairs in the hash recursively, so that actions on the duplicate do not affect the original hash:
hash = {b: 2} # => {b: 2} dup, deep = hash.dup, hash.deep_dup # => {b: 2}, {b: 2}
deep[:b] = 14 # => {b: 14} p hash # => {b: 2}
dup[:b] = 14 # => {b: 14} p hash # => {b: 14}
49 50 51 52 53 |
# File 'lib/reactive_support/core_ext/object/deep_dup.rb', line 49 def deep_dup self.each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end |
#present? ⇒ Boolean
When called on a hash (or any enumerable), the #present? method returns true if the hash is not empty, even if its elements have blank values:
{ foo: :bar }.present? # => true
{ 'bar' => nil }.present? # => true
{}.present? # => false
82 83 84 |
# File 'lib/reactive_support/core_ext/object/blank.rb', line 82 def present? !blank? end |