Class: Class
Instance Method Summary collapse
-
#class_attribute(*attrs) ⇒ Object
Provides a way to make class attributes that inherit.
-
#remove_possible_method(method) ⇒ Object
Removes a method if it is defined.
Instance Method Details
#class_attribute(*attrs) ⇒ Object
Provides a way to make class attributes that inherit. Pass in symbols for attribute names
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/volt/extra_core/class.rb', line 4 def class_attribute(*attrs) attrs.each do |name| define_singleton_method(name) { nil } ivar = "@#{name}" define_singleton_method("#{name}=") do |val| singleton_class.class_eval do remove_possible_method(name) define_method(name) { val } end val end end end |
#remove_possible_method(method) ⇒ Object
Removes a method if it is defined.
22 23 24 25 26 |
# File 'lib/volt/extra_core/class.rb', line 22 def remove_possible_method(method) if method_defined?(method) || private_method_defined?(method) undef_method(method) end end |