lib/virtus/extensions.rb
# Defines an attribute on an object's class
#
# @example
#    class Book
#      include Virtus
#
#      attribute :title,        String
#      attribute :author,       String
#      attribute :published_at, DateTime
#      attribute :page_count,   Integer
#      attribute :index                   # defaults to Object
#    end
#
# @param [Symbol] name
#   the name of an attribute
#
# @param [Class] type
#   the type class of an attribute
#
# @param [#to_hash] options
#   the extra options hash
#
# @return [self]
#
# @see Attribute.build
#
# @api public
Defines an attribute on an object's class
Defines an attribute on an object ' s class
def attribute(*args)
      opts = args.dup.extract_options!
      attributes = [Attribute.build(*args)].flatten
      attributes.each {|attribute| virtus_add_attribute(attribute) }
      clazz_meth = opts.delete(:as) if opts[:as]
      create_attribute_group clazz_meth, attributes if clazz_meth
      self
    end
def attribute ( * args ) opts = args . dup . extract_options! attributes = [ Attribute . build ( * args ) ] . flatten attributes . each { | attribute | virtus_add_attribute ( attribute ) } clazz_meth = opts . delete ( :as ) if opts [ :as ] create_attribute_group clazz_meth , attributes if clazz_meth self end
Defines an attribute on an object's class
Defines an attribute on an object ' s class
None
self
args
<not_specific>
<not_specific>
options the extra options hash
options the extra options hash
example
class Book include Virtus attribute :title, String attribute :author, String attribute :published_at, DateTime attribute :page_count, Integer attribute :index # defaults to Object end
class Book include Virtus attribute : title String attribute : author String attribute : published_at DateTime attribute : page_count Integer attribute : index # defaults to Object end
see
None
api
None