Class: Virtus::AttributesAccessor
- Inherits:
-
Module
- Object
- Module
- Virtus::AttributesAccessor
- Defined in:
- lib/virtus/attributes_accessor.rb
Overview
Host attribute accessor methods
Instance Attribute Summary collapse
-
#inspect ⇒ String
readonly
The inspect value of this Module.
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.
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
30 31 32 33 |
# File 'lib/virtus/attributes_accessor.rb', line 30 def initialize(name) super() @inspect = "#{name}::AttributesAccessor" end |
Instance Attribute Details
#inspect ⇒ String (readonly)
The inspect value of this Module
This provides meaningful output when inspecting the ancestors of a class/module that includes this module
23 24 25 |
# File 'lib/virtus/attributes_accessor.rb', line 23 def inspect @inspect 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
44 45 46 47 48 |
# File 'lib/virtus/attributes_accessor.rb', line 44 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
59 60 61 62 63 |
# File 'lib/virtus/attributes_accessor.rb', line 59 def define_writer_method(attribute, method_name, visibility) define_method(method_name) { |value| attribute.set(self, value) } send(visibility, method_name) self end |