Module: ThemeJuice::HashHelper

Defined in:
lib/theme-juice/helpers/hash_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/theme-juice/helpers/hash_helper.rb', line 14

def method_missing(method, *args, &block)
  super if method == "symbolize_keys"
  if to_ostruct.respond_to? method
    to_ostruct.send method
  else
    super
  end
end

Instance Method Details

#symbolize_keysObject



6
7
8
9
10
11
# File 'lib/theme-juice/helpers/hash_helper.rb', line 6

def symbolize_keys
  inject({}) do |acc, (key, value)|
    acc[(key.to_sym rescue key) || key] = value
    acc
  end
end

#to_ostruct(acc = self) ⇒ Object



23
24
25
# File 'lib/theme-juice/helpers/hash_helper.rb', line 23

def to_ostruct(acc = self)
  OpenStruct.new acc
end