Class: Ruote::HashWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/util/hashdot.rb

Constant Summary collapse

DELEGATED =
%w[ delete size length [] []= ]

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ HashWrapper


32
33
34
35
# File 'lib/ruote/util/hashdot.rb', line 32

def initialize(h)

  @h = h
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruote/util/hashdot.rb', line 42

def method_missing(m, *args)

  k = m.to_s

  return @h.send(k, *args) if DELEGATED.include?(k)

  if k[-1, 1] == '=' && args.size == 1
    @h[k[0..-2]] = args.first
  elsif args.size == 0
    @h[k]
  end
end

Instance Method Details

#to_hObject


37
38
39
40
# File 'lib/ruote/util/hashdot.rb', line 37

def to_h

  @h
end