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
25
26
27
# File 'lib/configer/object.rb', line 9

def method_missing( method_name, *args )

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

  else
    #> respond to method only if no value present
    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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/configer/object.rb', line 58

def self.parse(obj)

  return case

           when obj.class <= Hash
             obj.reduce(self.new){|m,h| m.merge!( (h[0].class <= Symbol ? h[0].to_s : h[0] ) => self.parse(h[1]) ) ;m}

           when obj.class <= Array
             obj.map{|o| self.parse(o) }

           else
             obj

         end

end

Instance Method Details

#[](key) ⇒ Object



47
48
49
50
# File 'lib/configer/object.rb', line 47

def [] key
  key = key.to_s if key.class <= Symbol
  super || super(key.to_sym)
end

#[]=(key, value) ⇒ Object



52
53
54
55
# File 'lib/configer/object.rb', line 52

def []= key,value
  key = key.to_s if key.class <= Symbol
  super
end