|
Revision 6108, 1.0 kB
(checked in by rick, 2 years ago)
|
Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. [Rick]
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
class Class |
|---|
| 4 |
def cattr_reader(*syms) |
|---|
| 5 |
syms.flatten.each do |sym| |
|---|
| 6 |
next if sym.is_a?(Hash) |
|---|
| 7 |
class_eval(<<-EOS, __FILE__, __LINE__) |
|---|
| 8 |
unless defined? @@ |
|---|
| 9 |
@@ |
|---|
| 10 |
end |
|---|
| 11 |
|
|---|
| 12 |
def self. |
|---|
| 13 |
@@ |
|---|
| 14 |
end |
|---|
| 15 |
|
|---|
| 16 |
def |
|---|
| 17 |
@@ |
|---|
| 18 |
end |
|---|
| 19 |
EOS |
|---|
| 20 |
end |
|---|
| 21 |
end |
|---|
| 22 |
|
|---|
| 23 |
def cattr_writer(*syms) |
|---|
| 24 |
options = syms.last.is_a?(Hash) ? syms.pop : {} |
|---|
| 25 |
syms.flatten.each do |sym| |
|---|
| 26 |
class_eval(<<-EOS, __FILE__, __LINE__) |
|---|
| 27 |
unless defined? @@ |
|---|
| 28 |
@@ |
|---|
| 29 |
end |
|---|
| 30 |
|
|---|
| 31 |
def self. |
|---|
| 32 |
@@ |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
def |
|---|
| 37 |
@@ |
|---|
| 38 |
end |
|---|
| 39 |
" unless options[:instance_writer] == false } |
|---|
| 40 |
EOS |
|---|
| 41 |
end |
|---|
| 42 |
end |
|---|
| 43 |
|
|---|
| 44 |
def cattr_accessor(*syms) |
|---|
| 45 |
cattr_reader(*syms) |
|---|
| 46 |
cattr_writer(*syms) |
|---|
| 47 |
end |
|---|
| 48 |
end |
|---|