Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/value-1.0.rb

Overview

Ruby’s Module class, extended to add #Value, a way of creating value object classes.

Instance Method Summary collapse

Instance Method Details

#Value(first, *rest, options = {}) ⇒ Object

Marks the module as a Value object with attributes FIRST and REST. This’ll add protected attribute readers for each of these attributes and a private method #attributes that returns the Value::Attributes themselves, include Value::Comparable if COMPARABLE isn’t falsy, and finally include Value.



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/value-1.0.rb', line 121

def Value(first, *rest)
  options = Hash === rest.last ? rest.pop : {}
  attributes = Value::Attributes.new(first, *rest.dup.push({:comparable => options[:comparable]}))
  attr_reader(*attributes)
  protected(*attributes)
  define_method :attributes do
    attributes
  end
  private :attributes
  include Value::Comparable if options[:comparable]
  include Value
  self
end