No commit activity in last 3 years
No release in over 3 years
Combined reader/writer accessors in Ruby, ideal for chaining or DSLs. This is useful for when you want to expose a DSL to an external file (think Rakefile like setup) and want to hide the fact the code is actually running inside a class with a structure.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.1, >= 1.1.1
~> 3.9, >= 3.9.0
~> 3.10, >= 3.10.0
~> 1.4, >= 1.4.2
~> 2.0, >= 2.0.0
~> 0.20, >= 0.20.0
~> 0.8, >= 0.8.0
 Project Readme

attr_combined_accessor Build Status Coverage Status RubyGems Version

Combined reader/writer accessors in Ruby, ideal for chaining or DSLs.

Installing

You can install this gem via RubyGems:

gem install attr_combined_accessor

Using

Sometimes you really need to be able to set and get without the limitations of Ruby's default accessors and the equals sign. This is where attr_combined_accessor comes in!

require 'attr_combined_accessor'

class MyAmazingClass
  attr_combined_accessor :foo, :bar
end

And now you can use them:

my_amazing_class = MyAmazingClass.new
my_amazing_class.foo # => nil
my_amazing_class.foo('foo')
my_amazing_class.foo # => 'foo'

The attr_combined_accessor gem returns self from the accessor, which makes chaining setters possible:

my_amazing_class = MyAmazingClass.new
my_amazing_class.foo('foo').bar('bar')
my_amazing_class.foo # => 'foo'
my_amazing_class.bar # => 'bar'

It also creates the standard attr_writer for the places where you want readability and don't need the DSL or chaining style:

my_amazing_class = MyAmazingClass.new
my_amazing_class.foo = 'foo'
my_amazing_class.foo # => 'foo'
my_amazing_class.foo('notfoo!')
my_amazing_class.foo # => 'notfoo!'

License

This project is licensed via MIT license.