Class: Hash

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hash.rb', line 14

def method_missing(method, *args)
  return super(method, *args) unless to_dot?

  prop = create_prop(method)

  if self[prop].nil?
    self[prop] = self.delete(prop.to_s)
  end

  super(method, args) and return if self[prop].nil?

  if setter?(method)
    self[prop] = args.first
  else
    self[prop]
  end
end

Class Attribute Details

.use_dot_syntaxObject

Returns the value of attribute use_dot_syntax.



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

def use_dot_syntax
  @use_dot_syntax
end

Instance Attribute Details

#use_dot_syntaxObject

Returns the value of attribute use_dot_syntax.



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

def use_dot_syntax
  @use_dot_syntax
end

Instance Method Details

#to_dotObject



8
9
10
11
12
# File 'lib/hash.rb', line 8

def to_dot
  dotify_hash(self)

  self
end