Class: Virtus::AttributesAccessor
- Inherits:
-
Module
- Object
- Module
- Virtus::AttributesAccessor
- Defined in:
- lib/virtus/attributes_accessor.rb
Overview
Host attribute accessor methods
Instance Method Summary collapse
-
#define_reader_method(attribute, method_name, visibility) ⇒ self
private
Defines an attribute reader method.
-
#define_writer_method(attribute, method_name, visibility) ⇒ self
private
Defines an attribute writer method.
-
#initialize(name) ⇒ AttributesAccessor
constructor
private
Initialize a module for hosting Attribute access methods.
-
#inspect ⇒ String
The inspect value of this Module.
Constructor Details
#initialize(name) ⇒ AttributesAccessor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a module for hosting Attribute access methods
11 12 13 14 |
# File 'lib/virtus/attributes_accessor.rb', line 11 def initialize(name) super() @name = name end |
Instance Method Details
#define_reader_method(attribute, method_name, visibility) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines an attribute reader method
25 26 27 28 29 |
# File 'lib/virtus/attributes_accessor.rb', line 25 def define_reader_method(attribute, method_name, visibility) define_method(method_name) { attribute.get(self) } send(visibility, method_name) self end |
#define_writer_method(attribute, method_name, visibility) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines an attribute writer method
40 41 42 43 44 |
# File 'lib/virtus/attributes_accessor.rb', line 40 def define_writer_method(attribute, method_name, visibility) define_method(method_name) { |value| attribute.set(self, value) } send(visibility, method_name) self end |
#inspect ⇒ String
The inspect value of this Module
This provides meaningful output when inspecting the ancestors of a class/module that includes this module
63 64 65 |
# File 'lib/virtus/attributes_accessor.rb', line 63 def inspect "#{@name}::AttributesAccessor" end |