disu.se

ValueModule

Namespace

Top-level Namespace

Represents an immutable value object with an #initialize method, equality checks #== and #eql?, a #hash function, and an #inspect method.

Example: A Point Value Object
class Point
  Value :x, :y
end
Example: A Point Value Object with Public Accessors
class Point
  Value :x, :y
  public(*attributes)
end
Example: A Value Object with Optional Attributes
class Money
  Value :amount, [:currency, :USD]
end
Example: A Value Object with a Comparable Attribute
class Vector
  Value :a, :b, :comparable => :a
end

Children

Attributes

Keeps track of the structure of the attributes associated with a Value object.

Comparable

Module included by Module#Value when passed the :comparable option.

Instance Methods

initialize(*argumentsObject*){ … }?#

Creates a new value object, using arguments to set up the value’s required, optional, and splat attributes, and the given block, if given, if a block is desired.

Raises
ArgumentError

If arguments#length is less than the number of required attributes

ArgumentError

If arguments#length is greater than the number of required and optional attributes

==(otherValue)Boolean#

Returns true if the receiver’s class and all of its Attributes #== those of other.

hashFixnum#

Returns the hash value of the receiver’s class XORed with the hash value of the Array of the values of the Attributes of the receiver.

inspectString#

Returns the inspection of the receiver.

eql?Boolean#

This is an alias for #==.