Class: ConfId
- Inherits:
-
Object
- Object
- ConfId
- Defined in:
- lib/vimamsa/conf.rb
Overview
To get conf value: cnf.foo.bar.baz? cnf.foo.bar.baz! get(cnf.foo.bar.baz) (All get the same result)
Instance Method Summary collapse
-
#initialize(first) ⇒ ConfId
constructor
A new instance of ConfId.
- #method_missing(method_name, *args) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(first) ⇒ ConfId
Returns a new instance of ConfId.
43 44 45 |
# File 'lib/vimamsa/conf.rb', line 43 def initialize(first) @id = [first] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vimamsa/conf.rb', line 47 def method_missing(method_name, *args) # pp "asize:#{args.size}" if m = method_name.match(/(.*)=$/) @id << m[1].to_sym # pp [@id, args[0]] set(self, args[0]) return args[0] elsif m = method_name.match(/(.*)[\!\?]$/) @id << m[1].to_sym r = get(self) if r.class == Hash and r.empty? # The accessed key was not defined return nil else return r end else @id << method_name end return self end |
Instance Method Details
#to_a ⇒ Object
75 76 77 |
# File 'lib/vimamsa/conf.rb', line 75 def to_a return @id end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/vimamsa/conf.rb', line 71 def to_s @id.join(".") end |