Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple immutable value objects for ruby (the readme is longer than the code)
Ruby
tag: v1.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
VERSION
values.gemspec

README.md

Values is a tiny library for creating value objects in ruby. These mostly look like classes created using Struct, but fix two problems with those:

  • Struct constructors can take less than the default number of arguments and set other fields as nil: Point = Struct.new(:x,:y) Point.new(1) => #

  • Structs are also mutable: Point = Struct.new(:x,:y) p = Point.new(1,2) p.x = 2 p.x => 2

Values fixes both of these: Point = Value.new(:x, :y) Point.new(1) => SOME EXCEPTION

p = Point.new(1,2)
p.x = 1
=> SOME EXCEPTION
Something went wrong with that request. Please try again.