Sha256: 13ec06b7771724d20530c7d488651a8117a689d97930d0edac00fcda5f455798
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
= ImmutableStruct {<img src="https://travis-ci.org/stitchfix/immutable-struct.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/stitchfix/immutable-struct] Creates struct-like classes (that can build value objects) that do not have setters and also have better constructors than Ruby's built-in +Struct+. This is highly useful for creating presenters, non-database-related models, or other quick and dirty classes in your application. Instead of using a +Hash+ or +OpenStruct+, you can create a bit more clarity around your types by using +ImmutableStruct+, which is almost as convienient. == Install Add to your +Gemfile+: gem 'immutable-struct' Then install: bundle install If not using bundler, just use RubyGems: gem install immutable-struct == To use Person = StitchFix::ImmutableStruct.new(:name, :age, :job, :active?) do def minor? age < 18 end end p = Person.new(name: "Dave", # name will be 'Dave' age: 40, # age will be 40 # job is omitted, so will be nil active: true) # active and active? will be true p.name # => "Dave" p.age # => 40 p.active? # => true p.minor? # => false You can also treat the interior as a normal class definition. == Links * rdoc[http://stitchfix.github.io/immutable-struct] * source[http://github.com/stitchfix/immutable-struct] * blog[http://technology.stitchfix.com/blog/2013/12/20/presenters-delegation-vs-structs/]
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
immutable-struct-2.0.0 | README.rdoc |