Class: Configer::Object

Inherits:
Hash
  • Object
show all
Defined in:
lib/configer/object.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/configer/object.rb', line 9

def method_missing( method_name, *args )

  if method_name.to_s[-1] == '='
    self[method_name.to_s[0..-2]]= *args
    return self[method_name.to_s[0..-2]]
  else

    if self[method_name.to_s].nil? && self.respond_to?(method_name)
      return self.__send__(method_name)
    else
      return self[method_name.to_s]
    end

  end

end

Class Method Details

.parse(obj) ⇒ Object

> parse object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/configer/object.rb', line 55

def self.parse obj
  raise(ArgumentError,"input must be Hash") unless obj.is_a? ::Hash

  hash = self.new.merge!(obj)
  hash.each_pair do |key,value|
    if value.class <= ::Hash
      hash[key]= self.parse(value)
    end
  end
  return hash

end

Instance Method Details

#[](key) ⇒ Object



44
45
46
47
# File 'lib/configer/object.rb', line 44

def [] key
  key = key.to_s
  super
end

#[]=(key, value) ⇒ Object



49
50
51
52
# File 'lib/configer/object.rb', line 49

def []= key,value
  key = key.to_s
  super
end