Class: Hash

Inherits:
Object show all
Includes:
Compact, Cross, EnsureKeys, Extract, Extras
Defined in:
lib/vex/base/hash/easy_access.rb,
lib/vex/base/hash/inspect.rb,
lib/vex/base/hash/ensure_keys.rb,
lib/vex/base/hash/simple_access_methods.rb,
lib/vex/base/hash/extract.rb,
lib/vex/base/hash/compact.rb,
lib/vex/base/object/insp.rb,
lib/vex/base/hash/extras.rb,
lib/vex/base/hash/cross.rb

Overview

  • allows to use hash.xx.yy where you would have to use

hash[:yy] etc.

  • supports

    hash.xx?

as a shortcut for hash.key?(:xx) || hash.key?(“xx”)

  • does not support assignment, though; i.e.

    hash.yy = zz

will raise a NoMethodError.

Direct Known Subclasses

LocalConf

Defined Under Namespace

Modules: Compact, Cross, EasyAccess, EnsureKeys, Etest, Extract, Extras, SimpleAccessMethods

Instance Method Summary collapse

Methods included from Cross

#cross

Methods included from Extras

#delete_all, #hmap, included, #select_entries

Methods included from Compact

#compact, #compact!

Methods included from Extract

#extract, #extract!

Methods included from EnsureKeys

#keys?

Instance Method Details

#easy_accessObject


77
78
79
# File 'lib/vex/base/hash/easy_access.rb', line 77

def easy_access
  dup.easy_access!
end

#easy_access!Object


81
82
83
84
# File 'lib/vex/base/hash/easy_access.rb', line 81

def easy_access!
  # extend always returns self
  extend(EasyAccess)
end

#easy_accessible?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'lib/vex/base/hash/easy_access.rb', line 86

def easy_accessible?
  @easy_accessible
end

#inspObject


47
48
49
# File 'lib/vex/base/object/insp.rb', line 47

def insp
  self.class == Hash && instance_variables.empty? ? insp_body : super
end

#inspectObject


3
4
5
6
7
8
9
# File 'lib/vex/base/hash/inspect.rb', line 3

def inspect
  "{" + to_a.sort_by do |k, v|
    k.to_s
  end.map do |k,v| 
    "#{k.inspect} => #{v.inspect}" 
  end.join(", ") + "}"
end

#with_simple_accessObject


2
3
4
5
# File 'lib/vex/base/hash/simple_access_methods.rb', line 2

def with_simple_access
  Deprecation.report "Hash#with_simple_access", "Hash#easy_access"
  easy_access!
end