Class: Class
Overview
Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of their parents’ attributes, instead of just a pointer to the same. This means that the child can add elements to, for example, an array without those additions being shared with either their parent, siblings, or children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.
Instance Method Summary
collapse
#fixturize!, #fixturize_description_args, included, #method_missing_with_fixture_check
Instance Method Details
#cattr_accessor(*syms) ⇒ Object
54
55
56
57
|
# File 'lib/can_has_fixtures/vendor/class_ext.rb', line 54
def cattr_accessor(*syms)
cattr_reader(*syms)
cattr_writer(*syms)
end
|
#cattr_reader(*syms) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/can_has_fixtures/vendor/class_ext.rb', line 13
def cattr_reader(*syms)
syms.flatten.each do |sym|
next if sym.is_a?(Hash)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
@@#{sym} = nil
end
def self.#{sym}
@@#{sym}
end
def #{sym}
@@#{sym}
end
EOS
end
end
|
#cattr_writer(*syms) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/can_has_fixtures/vendor/class_ext.rb', line 32
def cattr_writer(*syms)
options = syms.last.is_a?(Hash) ? syms.pop : {}
syms.flatten.each do |sym|
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
@@#{sym} = nil
end
def self.#{sym}=(obj)
@@#{sym} = obj
end
#{"
def #{sym}=(obj)
@@#{sym} = obj
end
" unless options[:instance_writer] == false }
EOS
end
end
|