Module: Virtus::InstanceMethods
- Defined in:
- lib/virtus/instance_methods.rb
Overview
Instance methods that are added when you include Virtus
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.
-
#attributes ⇒ Hash
Returns a hash of all publicly accessible attributes.
-
#attributes=(attributes) ⇒ Hash
Mass-assign attribute values.
-
#freeze ⇒ self
Freeze object.
-
#initialize(attributes = nil) ⇒ undefined
private
Set attributes during initialization of an object.
-
#to_hash ⇒ Hash
Returns a hash of all publicly accessible attributes.
Instance Method Details
#[](name) ⇒ Object
Returns a value of the attribute with the given name
37 38 39 |
# File 'lib/virtus/instance_methods.rb', line 37 def [](name) get_attribute(name) end |
#[]=(name, value) ⇒ Object
Sets a value of the attribute with the given name
64 65 66 |
# File 'lib/virtus/instance_methods.rb', line 64 def []=(name, value) set_attribute(name, value) end |
#attributes ⇒ Hash
Returns a hash of all publicly accessible attributes
84 85 86 |
# File 'lib/virtus/instance_methods.rb', line 84 def attributes get_attributes(&:public_reader?) end |
#attributes=(attributes) ⇒ Hash
Mass-assign attribute values
Keys in the attributes
param can be symbols or strings. All referenced Attribute writer methods will be called. Non-attribute setter methods on the receiver will be called.
111 112 113 |
# File 'lib/virtus/instance_methods.rb', line 111 def attributes=(attributes) set_attributes(attributes) end |
#freeze ⇒ self
Freeze object
156 157 158 159 |
# File 'lib/virtus/instance_methods.rb', line 156 def freeze set_defaults super end |
#initialize(attributes = nil) ⇒ undefined
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 attributes during initialization of an object
14 15 16 |
# File 'lib/virtus/instance_methods.rb', line 14 def initialize(attributes = nil) self.attributes = attributes if attributes end |
#to_hash ⇒ Hash
Returns a hash of all publicly accessible attributes
131 132 133 |
# File 'lib/virtus/instance_methods.rb', line 131 def to_hash attributes end |