Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/cattr.rb
Instance Method Summary collapse
Instance Method Details
#cattr_accessor(*meths) ⇒ Object
2 3 4 5 |
# File 'lib/cattr.rb', line 2 def cattr_accessor(*meths) cattr_writer(*meths) cattr_reader(*meths) end |
#cattr_reader(*meths) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/cattr.rb', line 6 def cattr_reader(*meths) meths.each do |meth| self.class.send(:define_method, meth) do return nil unless class_variable_defined? "@@#{meth}" return class_variable_get "@@#{meth}" end end end |
#cattr_writer(*meths) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/cattr.rb', line 14 def cattr_writer(*meths) meths.each do |meth| self.class.send(:define_method, :"#{meth}=") do |arg| class_variable_set("@@#{meth}", arg) end end end |