module Virtus::ValueObject
Include this Module for Value Object semantics
The idea is that instances should be immutable and compared based on state
(rather than identity, as is typically the case)
@example
class GeoLocation include Virtus::ValueObject attribute :latitude, Float attribute :longitude, Float end location = GeoLocation.new(:latitude => 10, :longitude => 100) same_location = GeoLocation.new(:latitude => 10, :longitude => 100) location == same_location #=> true hash = { location => :foo } hash[same_location] #=> :foo
Private Class Methods
included(base)
click to toggle source
Callback to configure including Class as a Value Object
Including Class will include Virtus and have additional
value object semantics defined in this module
@return [Undefined]
TODO: stacking modules is getting painful
time for Facets' module_inheritance, ActiveSupport::Concern or the like
@api private
# File lib/virtus/value_object.rb, line 33 def self.included(base) Virtus.warn "Virtus::ValueObject is deprecated and will be removed in 1.0.0 #{caller.first}" base.instance_eval do include Virtus include InstanceMethods extend ClassMethods extend AllowedWriterMethods private :attributes= end end