Instance methods that are added when you include Virtus
Returns a value of the attribute with the given name
@example
class User include Virtus attribute :name, String end user = User.new(:name => 'John') user[:name] # => "John"
@param [Symbol] name
a name of an attribute
@return [Object]
a value of an attribute
@api public
# File lib/virtus/instance_methods.rb, line 94 def [](name) public_send(name) end
Sets a value of the attribute with the given name
@example
class User include Virtus attribute :name, String end user = User.new user[:name] = "John" # => "John" user.name # => "John"
@param [Symbol] name
a name of an attribute
@param [Object] value
a value to be set
@return [Object]
the value set on an object
@api public
# File lib/virtus/instance_methods.rb, line 121 def []=(name, value) public_send("#{name}=", value) end
Freeze object
@return [self]
@api public
@example
class User include Virtus attribute :name, String attribute :age, Integer end user = User.new(:name => 'John', :age => 28) user.frozen? # => false user.freeze user.frozen? # => true
@api public
# File lib/virtus/instance_methods.rb, line 146 def freeze set_default_attributes! super end
Reset an attribute to its default
@return [self]
@api public
@example
class User include Virtus attribute :age, Integer, default: 21 end user = User.new(:name => 'John', :age => 28) user.age = 30 user.age # => 30 user.reset_attribute(:age) user.age # => 21
@api public
# File lib/virtus/instance_methods.rb, line 172 def reset_attribute(attribute_name) attribute = attribute_set[attribute_name] attribute.set_default_value(self) if attribute self end
Generated with the Darkfish Rdoc Generator 2.