Module: Oat::ClassAttribute
- Included in:
- Serializer
- Defined in:
- lib/support/class_attribute.rb
Instance Method Summary collapse
Instance Method Details
#class_attribute(*attrs) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/support/class_attribute.rb', line 3 def class_attribute(*attrs) attrs.each do |name| class_eval " def self.\#{name}() nil end\n\n def self.\#{name}=(val)\n singleton_class.class_eval do\n define_method(:\#{name}) { val }\n end\n\n if singleton_class?\n class_eval do\n def \#{name}\n defined?(@\#{name}) ? @\#{name} : singleton_class.\#{name}\n end\n end\n end\n val\n end\n RUBY\n\n end\nend\n", __FILE__, __LINE__ + 1 |
#singleton_class ⇒ Object
27 28 29 30 31 |
# File 'lib/support/class_attribute.rb', line 27 def singleton_class class << self self end end |
#singleton_class? ⇒ Boolean
33 34 35 |
# File 'lib/support/class_attribute.rb', line 33 def singleton_class? ancestors.first != self end |