Class: Hash

Inherits:
Object
  • Object
show all
Includes:
Xqsr3::HashUtilities::DeepTransform
Defined in:
lib/xqsr3/doc_.rb,
lib/xqsr3/extensions/hash/match.rb,
lib/xqsr3/extensions/hash/slice.rb,
lib/xqsr3/extensions/hash/except.rb,
lib/xqsr3/extensions/hash/except.rb,
lib/xqsr3/extensions/hash/has_match.rb,
lib/xqsr3/extensions/hash/deep_transform.rb

Overview

Standard class, extended with methods:

  • Hash#deep_transform

  • Hash#has_match?

  • Hash#match

Direct Known Subclasses

Xqsr3::Containers::MultiMap

Instance Method Summary collapse

Methods included from Xqsr3::HashUtilities::DeepTransform

#deep_transform, #deep_transform!

Instance Method Details

#except(*keys_to_delete) ⇒ Object

Obtains a copy of the instance wherein any key-value pairs matching the keys specified in keys_to_delete are removed



26
27
28
29
# File 'lib/xqsr3/extensions/hash/except.rb', line 26

def except(*keys_to_delete)

  self.dup.except!(*keys_to_delete)
end

#except!(*keys_to_delete) ⇒ Object

Removes from the instance any key-value pairs matching the keys specified in keys_to_delete



8
9
10
11
12
13
14
15
16
# File 'lib/xqsr3/extensions/hash/except.rb', line 8

def except!(*keys_to_delete)

  keys_to_delete.each do |key|

    self.delete key
  end

  self
end

#has_match?(re, **options) ⇒ Boolean

Extended method implemented by Xqsr3::HashUtilities::KeyMatching

Signature

  • Parameters:

    • re (Regexp) The regular expression

    • options (Hash) See Xqsr3::HashUtilities::KeyMatching

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/xqsr3/extensions/hash/has_match.rb', line 13

def has_match? re, **options

  return ::Xqsr3::HashUtilities::KeyMatching.has_match? self, re, **options
end

#match(re, **options) ⇒ Object

Extended method implemented by Xqsr3::HashUtilities::KeyMatching

Signature

  • Parameters:

    • re (Regexp) The regular expression

    • options (Hash) See Xqsr3::HashUtilities::KeyMatching



13
14
15
16
# File 'lib/xqsr3/extensions/hash/match.rb', line 13

def match re, **options

  return ::Xqsr3::HashUtilities::KeyMatching.match self, re, **options
end

#slice(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/xqsr3/extensions/hash/slice.rb', line 6

def slice(*args)

  r = {}

  args.each do |arg|

    if self.has_key? arg

      r[arg] = self[arg]
    end
  end

  r
end