Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/carioca/services/configuration.rb

Overview

overwriting Hash class

Direct Known Subclasses

Carioca::Services::Settings

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

pretty accessor for hash record like ahash => ahash.key r/w accessor



45
46
47
48
49
50
51
# File 'lib/carioca/services/configuration.rb', line 45

def method_missing(name, *args, &block)
  if name.to_s =~ /(.+)=$/
    self[$1.to_sym] = args.first
  else
    self[name.to_sym]
  end
end

Instance Method Details

#deep_symbolizeObject

recursively transform Hash keys form String to Symbols come from Rails code exist in Ruby 2.0



33
34
35
36
37
38
39
40
# File 'lib/carioca/services/configuration.rb', line 33

def deep_symbolize
  target = dup
  target.inject({}) do |memo, (key, value)|
    value = value.deep_symbolize if value.is_a?(Hash)
    memo[key.to_sym] = value
    memo
  end
end