Project

bruv

0.0
No commit activity in last 3 years
No release in over 3 years
Simple module adding helper methods for generating attr_readers with optional procs and initialize method.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0
 Project Readme

Bruv

Write Ruby classes with less code. Bruv is a simple module which adds helper methods for defining class instance variables with reader methods and optional procs for processing data. Also defines an initialize method.

Installation

Add this line to your application's Gemfile:

gem 'bruv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bruv

Usage

Just include the module into a class and use attribute and attributes to define class instance variables like:

class MyClass
  include Bruv
  attribute :name
  attribute :tag, ->(d) { d.capitalize }
  attributes :type, :category
end

mc = MyClass.new('Hammer', 'bargain', 'tools', 'basic')
mc.name     # => 'Hammer'
mc.tag      # => 'Bargain'
mc.type     # => 'tools'
mc.category # => 'basic'

# or

mc = MyClass.new('Hammer', 'bargain')
mc.name     # => 'Hammer'
mc.date     # => 'Bargain'
mc.type     # => nil
mc.category # => nil

In case the number of arguments passed into initialize is greater than the number of instance variables defined with argument and arguments methods a BruvArgumentError is raised.

class MyClass
  include Bruv
  attributes :type, :category
end

MyClass.new('tools', 'basic', 'bargain') # => Bruv::BruvArgumentError: Number of arguments exceeds number of instance variables for: MyClass

License

The gem is available as open source under the terms of the MIT License.