Sha256: 962974f427cf572731e6a5c6cfa96f3159b280811c4a0e74c9c56b4312e3b605

Contents?: true

Size: 623 Bytes

Versions: 3

Compression:

Stored size: 623 Bytes

Contents

require "tfg/support/deep_hash_accessor"

class Hash
  # Allows chaining of keys through nested hashes.
  #
  # ```ruby
  # hash = {foo: true, bar: {baz: {qux: false}}}
  #
  # hash.deep[:foo] #=> true
  # hash.deep[:bar, :baz, :qux] #=> false
  # ```
  #
  # When the chain of keys is incomplete `nil` will be returned.
  #
  # ```ruby
  # hash[:bar, :qux] #=> nil
  # ```
  #
  # Assignment is also possible, and the key chain will be created
  # if needed.
  #
  # ```ruby
  # hash = {}
  # hash[:foo, :bar] = true
  # hash #=> {foo: {bar: true}}
  # ```
  def deep
    TFG::Support::DeepHashAccessor.new(self)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tfg_support-1.1.1 lib/tfg/support/core_ext/hash/deep.rb
tfg_support-1.0.1 lib/tfg/support/core_ext/hash/deep.rb
tfg_support-1.0.0 lib/tfg/support/core_ext/hash/deep.rb