Module: Virtus::ClassMethods
- Defined in:
- lib/virtus/class_methods.rb
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Virtus::Attributes::Object
Defines an attribute on an object’s class.
-
#attributes ⇒ Hash
Returns all the attributes defined on a Class.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Virtus::Attributes::Object
Defines an attribute on an object’s class.
Usage:
class Book
include Virtus
attribute :title, String
attribute :author, String
attribute :published_at, DateTime
attribute :page_count, Integer
end
28 29 30 31 |
# File 'lib/virtus/class_methods.rb', line 28 def attribute(name, type, = {}) attribute_klass = Virtus.determine_type(type) attributes[name] = attribute_klass.new(name, self, ) end |
#attributes ⇒ Hash
Returns all the attributes defined on a Class.
39 40 41 |
# File 'lib/virtus/class_methods.rb', line 39 def attributes @attributes ||= {} end |