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(" def self.\#{sym}\n @\#{sym}\n end\n\n def \#{sym}\n result = self.class.\#{sym}\n \#{\n \"\n if result.is_a?(Array)\n # Get the value from our ancestor if there is one.\n if self.class.superclass.respond_to? :\#{sym}\n result << self.class.superclass.\#{sym}\n end\n result.flatten!\n end\n if result.is_a?(Hash)\n # Get the value from our ancestor if there is one.\n if self.class.superclass.respond_to? :\#{sym}\n result = self.class.superclass.\#{sym}.merge(result)\n end\n end\n \" if options[:inheritable] \n }\n result\n end\n END\nend\n", __FILE__, __LINE__)
|