ImmutableRecord
ImmutableRecord provides simple immutable data structures with accessor
methods and keyword argument initialization.
Installation
Add this line to your application's Gemfile:
gem 'immutable_record'
And then execute:
$ bundle
Or install it yourself as:
$ gem install immutable_record
Usage
Example:
Item = ImmutableRecord.new(:foo, :bar)
item = Item.new(foo:1, bar:2)
Item.new(foo:1, bar:2).eql?(Item.new(foo:1, bar:2))
Item.new(foo:1, bar:2).eql?(Item.new(foo:1, bar:3))
item.foo
{
Item.new(foo: 1, bar: 2) => "yay!"
}.fetch(Item.new(foo: 1, bar: 2))
item.clone(foo: "changed")
item.clone {|bar:,**| {bar: bar + 1}}
item
class AwesomeRecord < ImmutableRecord.new(:foo, :bar)
end
ar = AwesomeRecord.new(foo: 1, bar: 3)
Contributing