Module Virtus::InstanceMethods
In: lib/virtus/instance_methods.rb

Instance methods that are added when you include Virtus

Methods

Classes and Modules

Module Virtus::InstanceMethods::Constructor
Module Virtus::InstanceMethods::MassAssignment

Public Instance methods

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

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

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

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

Set default attributes

@return [self]

@api private

Set default attributes even lazy ones

@return [self]

@api public

[Validate]