Class: Initializer::Attribute
- Inherits:
-
Object
- Object
- Initializer::Attribute
- Defined in:
- lib/initializer/macro.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#target_class ⇒ Object
readonly
Returns the value of attribute target_class.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Class Method Summary collapse
Instance Method Summary collapse
- #define ⇒ Object
- #define_getter ⇒ Object
- #define_setter ⇒ Object
-
#initialize(target_class, name, visibility) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(target_class, name, visibility) ⇒ Attribute
Returns a new instance of Attribute.
115 116 117 118 119 |
# File 'lib/initializer/macro.rb', line 115 def initialize(target_class, name, visibility) @target_class = target_class @name = name @visibility = visibility end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
112 113 114 |
# File 'lib/initializer/macro.rb', line 112 def name @name end |
#target_class ⇒ Object (readonly)
Returns the value of attribute target_class.
111 112 113 |
# File 'lib/initializer/macro.rb', line 111 def target_class @target_class end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
113 114 115 |
# File 'lib/initializer/macro.rb', line 113 def visibility @visibility end |
Class Method Details
.define(target_class, name, visibility) ⇒ Object
121 122 123 124 |
# File 'lib/initializer/macro.rb', line 121 def self.define(target_class, name, visibility) instance = new target_class, name, visibility instance.define end |
Instance Method Details
#define ⇒ Object
126 127 128 129 |
# File 'lib/initializer/macro.rb', line 126 def define define_getter if [:reader, :accessor].include? visibility define_setter if [:writer, :accessor].include? visibility end |
#define_getter ⇒ Object
131 132 133 134 135 136 |
# File 'lib/initializer/macro.rb', line 131 def define_getter name = self.name target_class.send :define_method, name do instance_variable_get("@#{name}") end end |
#define_setter ⇒ Object
138 139 140 141 142 143 |
# File 'lib/initializer/macro.rb', line 138 def define_setter name = self.name target_class.send :define_method, "#{name}=" do |value| instance_variable_set("@#{name}", value) end end |