Class: NetAppManageability::NAMHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/net_app_manageability/nam_hash.rb

Constant Summary collapse

STRIP_PREFIX =
"nam_"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sym_keys = false, &block) ⇒ NAMHash

Returns a new instance of NAMHash.



11
12
13
14
15
16
17
18
# File 'lib/net_app_manageability/nam_hash.rb', line 11

def initialize(sym_keys = false, &block)
  @sym_keys = sym_keys
  super()
  unless block.nil?
    block.arity < 1 ? self.instance_eval(&block) : block.call(self)
    self.default = nil
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/net_app_manageability/nam_hash.rb', line 24

def method_missing(method_name, *args)
  key = method_name.to_s.sub(/^#{STRIP_PREFIX}/, "").tr('_', '-')
  if key[-1, 1] == '='
    return (self[key[0...-1]] = args[0]) unless @sym_keys
    return (self[key[0...-1].to_sym] = args[0])
  elsif args.length == 1
    return (self[key] = args[0]) unless @sym_keys
    return (self[key.to_sym] = args[0])
  else
    return self[key] unless @sym_keys
    return self[key.to_sym]
  end
end

Instance Attribute Details

#sym_keysObject

Returns the value of attribute sym_keys.



9
10
11
# File 'lib/net_app_manageability/nam_hash.rb', line 9

def sym_keys
  @sym_keys
end

Instance Method Details

#respond_to_missing?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/net_app_manageability/nam_hash.rb', line 38

def respond_to_missing?(*_args)
  true
end

#to_aryObject



20
21
22
# File 'lib/net_app_manageability/nam_hash.rb', line 20

def to_ary
  return [ self ]
end