0.0
No release in over 3 years
Low commit activity in last 3 years
Define an attribute on a class using an imperative API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Attribute

Define an attribute on a class using an imperative API.

Example

class Something
  Attribute::Define.(self, :some_accessor, :accessor)
  Attribute::Define.(self, :some_reader, :reader)
  Attribute::Define.(self, :some_writer, :writer)

  def initialize(some_accessor, some_reader, some_writer)
    @some_accessor = some_accessor
    @some_reader = some_reader
    @some_writer = some_writer
  end
end

something = Something.new(
  'Some Accessor Value',
  'Some Reader Value',
  'Some Writer Value'
)

## Accessor
puts something.some_accessor
# => "Some Accessor Value"

something.some_accessor = 'Some Other Value'
puts something.some_accessor
# => "Some Other Value"

## Reader
puts something.some_reader
# => "Some Reader Value"

something.some_reader = 'Some Other Value'
# => NoMethodError (undefined method `some_reader=' for #<Something:0x...>)

## Writer
puts something.some_writer
# => NoMethodError (undefined method `some_writer' for #<Something:0x...>)

something.some_writer = 'Some Other Value'

License

The attribute library is released under the MIT License.