Class: Hash

Inherits:
Object show all
Defined in:
lib/lib/helper/lib/hash.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/lib/helper/lib/hash.rb', line 13

def method_missing(m)
  if (@method_access.nil? ? (@@method_access rescue false) : @method_access)
    if has_key? m
      return self[m]
    elsif has_key? m.to_s
      return self[m.to_s]
    end
  end
  return old_m(m)
end

Instance Attribute Details

#method_accessObject

Returns the value of attribute method_access.



11
12
13
# File 'lib/lib/helper/lib/hash.rb', line 11

def method_access
  @method_access
end

Class Method Details

.method_accessObject



25
# File 'lib/lib/helper/lib/hash.rb', line 25

def method_access() @@method_access end

.method_access=(bool) ⇒ Object



24
# File 'lib/lib/helper/lib/hash.rb', line 24

def method_access=(bool) @@method_access = bool end

Instance Method Details

#extract(*ks) ⇒ Object



2
3
4
5
# File 'lib/lib/helper/lib/hash.rb', line 2

def extract(*ks)
  existing = keys & ks
  Hash[existing.zip(values_at(*existing))]
end

#has_shape?(shape) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/lib/helper/lib/hash.rb', line 6

def has_shape?(shape)
  all? do |k, v|
    Hash === v ? v.has_shape?(shape[k]) : shape[k] === v
  end
end

#old_mObject



12
# File 'lib/lib/helper/lib/hash.rb', line 12

alias :old_m :method_missing