Module: NanDoc::SharedAttrReader

Included in:
Helpers::NanDocHelpers::SiteMap
Defined in:
lib/nandoc/support/shared-attr-reader.rb

Instance Method Summary collapse

Instance Method Details

#shared_attr_reader(*list) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

this is a specialized form of delegator pattern: let one object use the responses from another object for a set of accessors



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nandoc/support/shared-attr-reader.rb', line 10

def shared_attr_reader *list
  fail('no inehiritance yet') if method_defined?(:shared=)
  sm = Module.new
  name = self.to_s+'::SharedAttrReaders'
  sing = class << sm; self end
  sing.send(:define_method, :name){name}
  sing.send(:alias_method, :inspect, :name)
  list.each do |attrib|
    sm.send(:define_method, attrib){ shared.send(attrib) }
  end
  fail('no') if method_defined?(:shared)
  define_method(:shared){ self }
  define_method(:shared=) do |source|
    sing = class << self; self end
    sing.send(:define_method, :shared){ source }
    sing.send(:include, sm) # wow cool that this works w/o having
                            # to Module#undef_method
    source
  end
  nil
end