Class: Hash

Inherits:
Object show all
Includes:
Compact, Cross, EnsureKeys, Extract, Extras
Defined in:
lib/vex/base/hash/slop.rb,
lib/vex/boot/hash.rb,
lib/vex/base/hash/cross.rb,
lib/vex/base/hash/extras.rb,
lib/vex/base/hash/compact.rb,
lib/vex/base/hash/extract.rb,
lib/vex/base/hash/inspect.rb,
lib/vex/base/hash/ensure_keys.rb,
lib/vex/base/object/insp.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

Argv, LocalConf

Defined Under Namespace

Modules: Compact, Cross, EnsureKeys, Etest, Extract, Extras, Slop

Instance Method Summary collapse

Methods included from EnsureKeys

#keys?

Methods included from Extract

#extract, #extract!

Methods included from Compact

#compact, #compact!

Methods included from Extras

#delete_all, #hmap, included, #select_entries

Methods included from Cross

#cross

Instance Method Details

#delete_multi(a0, *extras, &block) ⇒ Object Also known as: delete



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/vex/boot/hash.rb', line 4

def delete_multi(a0, *extras, &block)
  if extras.empty? || block_given?
    delete_single a0, *extras, &block
  else
    r = [ delete_single(a0) ]
    extras.each do |arg|
      r.push delete_single(arg)
    end
    r
  end
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

#slop!Object



63
64
65
# File 'lib/vex/base/hash/slop.rb', line 63

def slop!
  extend(Slop)
end

#sloppy?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/vex/base/hash/slop.rb', line 67

def sloppy?
  is_a?(Slop)
end