Class: Virtus::Attribute::Array

Inherits:
Collection show all
Defined in:
lib/virtus/attribute/array.rb

Overview

Array

Examples:

class Post
  include Virtus

  attribute :tags, Array
end

post = Post.new(:tags => %w(red green blue))

Constant Summary

Constants included from TypeLookup

TypeLookup::EXTRA_CONST_ARGS, TypeLookup::TYPE_FORMAT

Instance Attribute Summary

Attributes inherited from Collection

#member_type

Attributes inherited from Virtus::Attribute

#coercion_method, #default, #instance_variable_name, #name, #options, #reader_visibility, #writer_visibility

Instance Method Summary collapse

Methods inherited from Collection

#coerce, #initialize, merge_options, #new_collection

Methods inherited from Virtus::Attribute

build, #coerce, #define_accessor_methods, #define_reader_method, #define_writer_method, determine_type, #get, #get!, #initialize, #inspect, merge_options, #public_reader?, #public_writer?, #set, #set!, #value_coerced?

Methods included from DescendantsTracker

#add_descendant, #descendants

Methods included from TypeLookup

#determine_type, #primitive

Methods included from Options

#accept_options, #accepted_options, #options

Constructor Details

This class inherits a constructor from Virtus::Attribute::Collection

Instance Method Details

#coerce_and_append_member(collection, entry) ⇒ Array, Set

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.

Coerce a member of a source collection and append it to the target collection

Parameters:

  • collection (Array, Set)

    target collection to which the coerced member should be appended

  • entry (Object)

    the member that should be coerced and appended

Returns:

  • (Array, Set)

    collection with the coerced member appended to it



31
32
33
# File 'lib/virtus/attribute/array.rb', line 31

def coerce_and_append_member(collection, entry)
  collection << @member_type_instance.coerce(entry)
end