5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/doc_wrapper/sattr_accessor.rb', line 5
def sattr_reader (sym, options = {})
options = { :inheritable => false }.merge(options)
class_eval(<<-END, __FILE__, __LINE__)
def self.#{sym}
@#{sym}
end
def #{sym}
result = self.class.#{sym}
#{
"
if result.is_a?(Array)
# Get the value from our ancestor if there is one.
if self.class.superclass.respond_to? :#{sym}
result << self.class.superclass.#{sym}
end
result.flatten!
end
if result.is_a?(Hash)
# Get the value from our ancestor if there is one.
if self.class.superclass.respond_to? :#{sym}
result = self.class.superclass.#{sym}.merge(result)
end
end
" if options[:inheritable]
}
result
end
END
end
|