Class: ConfId

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/conf.rb

Instance Method Summary collapse

Constructor Details

#initialize(first) ⇒ ConfId

Returns a new instance of ConfId.



36
37
38
# File 'lib/vimamsa/conf.rb', line 36

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vimamsa/conf.rb', line 40

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_aObject



68
69
70
# File 'lib/vimamsa/conf.rb', line 68

def to_a
  return @id
end

#to_sObject



64
65
66
# File 'lib/vimamsa/conf.rb', line 64

def to_s
  @id.join(".")
end