Class: Docs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocs

Returns a new instance of Docs.



12
13
14
# File 'lib/docs.rb', line 12

def initialize
  @docs = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/docs.rb', line 16

def method_missing(method_name, *args)
  name = method_name.to_s
  if name.end_with?('=')
    name = name[0...(name.size - 1)]
    super unless @docs.key?(name)
    @docs[name] = args.first
    return args.first
  end
  super unless @docs.key?(name)
  @docs[name]
end

Instance Attribute Details

#docsObject (readonly)

Returns the value of attribute docs.



10
11
12
# File 'lib/docs.rb', line 10

def docs
  @docs
end

Instance Method Details

#add(name, content) ⇒ Object



28
29
30
31
32
# File 'lib/docs.rb', line 28

def add(name, content)
  return false if docs.key?(name)
  @docs[name] = content
  true
end