Module: Virtus::InstanceMethods
- Defined in:
- lib/virtus/instance_methods.rb
Instance Method Summary collapse
-
#attribute_get(name) ⇒ Object
Returns a value of the attribute with the given name.
-
#attribute_set(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 of attribute values.
-
#initialize(attributes = {}) ⇒ Object
private
Chains Class.new to be able to set attributes during initialization of an object.
Instance Method Details
#attribute_get(name) ⇒ Object
Returns a value of the attribute with the given name
25 26 27 |
# File 'lib/virtus/instance_methods.rb', line 25 def attribute_get(name) __send__(name) end |
#attribute_set(name, value) ⇒ Object
Sets a value of the attribute with the given name
41 42 43 |
# File 'lib/virtus/instance_methods.rb', line 41 def attribute_set(name, value) __send__("#{name}=", value) end |
#attributes ⇒ Hash
Returns a hash of all publicly accessible attributes
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/virtus/instance_methods.rb', line 68 def attributes attributes = {} self.class.attributes.each do |name, attribute| if self.class.public_method_defined?(name) attributes[name] = __send__(attribute.name) end end attributes end |
#attributes=(attributes) ⇒ Hash
Mass-assign of attribute values
54 55 56 57 58 59 60 |
# File 'lib/virtus/instance_methods.rb', line 54 def attributes=(attributes) attributes.each do |name, value| if self.class.public_method_defined?(writer_name = "#{name}=") __send__(writer_name, value) end end end |
#initialize(attributes = {}) ⇒ Object
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.
Chains Class.new to be able to set attributes during initialization of an object.
12 13 14 |
# File 'lib/virtus/instance_methods.rb', line 12 def initialize(attributes = {}) self.attributes = attributes end |