Class: Class
Instance Method Summary collapse
- #inherited_accessor(accessor, default = nil) ⇒ Object
- #inherited_property(accessor, default = nil) ⇒ Object
Instance Method Details
#inherited_accessor(accessor, default = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/core_ext.rb', line 76 def inherited_accessor(accessor, default = nil) instance_eval <<-RUBY, __FILE__, __LINE__ + 1 class << self; attr_writer :#{accessor}; end @#{accessor} = default def #{accessor} @#{accessor} ||= superclass.send(:#{accessor}).dup end RUBY end |
#inherited_property(accessor, default = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/core_ext.rb', line 48 def inherited_property(accessor, default = nil) instance_eval <<-RUBY, __FILE__, __LINE__ + 1 @#{accessor} = default def set_#{accessor}(value) @#{accessor} = value end alias #{accessor} set_#{accessor} def get_#{accessor} return @#{accessor} if instance_variable_defined?(:@#{accessor}) superclass.send(:get_#{accessor}) end RUBY # @path = default # # def set_path(value) # @path = value # end # alias_method path, set_path # def get_path # return @path if instance_variable_defined?(:path) # superclass.send(:path) # end end |