Module: Virtus::InstanceMethods
- Defined in:
- lib/virtus/instance_methods.rb
Overview
Instance methods that are added when you include Virtus
Defined Under Namespace
Modules: Constructor, MassAssignment
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns a value of the attribute with the given name.
-
#[]=(name, value) ⇒ Object
Sets a value of the attribute with the given name.
-
#freeze ⇒ self
Freeze object.
-
#reset_attribute(attribute_name) ⇒ self
Reset an attribute to its default.
-
#set_default_attributes ⇒ self
private
Set default attributes.
-
#set_default_attributes! ⇒ self
Set default attributes even lazy ones.
Instance Method Details
#[](name) ⇒ Object
Returns a value of the attribute with the given name
95 96 97 |
# File 'lib/virtus/instance_methods.rb', line 95 def [](name) public_send(name) end |
#[]=(name, value) ⇒ Object
Sets a value of the attribute with the given name
122 123 124 |
# File 'lib/virtus/instance_methods.rb', line 122 def []=(name, value) public_send("#{name}=", value) end |
#freeze ⇒ self
Freeze object
147 148 149 150 |
# File 'lib/virtus/instance_methods.rb', line 147 def freeze set_default_attributes! super end |
#reset_attribute(attribute_name) ⇒ self
Reset an attribute to its default
173 174 175 176 177 |
# File 'lib/virtus/instance_methods.rb', line 173 def reset_attribute(attribute_name) attribute = attribute_set[attribute_name] attribute.set_default_value(self) if attribute self end |
#set_default_attributes ⇒ 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.
Set default attributes
184 185 186 187 |
# File 'lib/virtus/instance_methods.rb', line 184 def set_default_attributes attribute_set.set_defaults(self) self end |
#set_default_attributes! ⇒ self
Set default attributes even lazy ones
194 195 196 197 |
# File 'lib/virtus/instance_methods.rb', line 194 def set_default_attributes! attribute_set.set_defaults(self, proc { |object, attribute| attribute.defined?(object) }) self end |