module Commutator::Util::Fluent
This module provides fluent accessors and wrappers, which are probably just terms I made up.
Usage: class Person
include Commutator::Util::Fluent fluent_accessor :first_name, :last_name, :pets fluent_wrapper :pets def initialize @pets = [] end
end
When called with an argument a fluent accessor will set a value and return the instance again. This allows chaining.
Ex: person = Person.new.first_name(‘Seymour’).last_name(‘Busses’) # => <#Person @first_name=‘Seymour’, @last_name=‘Busses’>
When called without an argument a fluent accessor will return the value it has. person = Person.new.first_name(‘Seymour’) person.first_name # => ‘Seymour’
A fluent wrapper allows you to manipulate “complex” objects and continue to chain calls. Fluent
wrappers start with a ‘with_` followed by the attribute name. Fluent
wrapper passes the value into a block.
Ex: person = Person.new
.first_name('Hi') .with_pets { |pets| pets << 'mittens' }