0.0
No commit activity in last 3 years
No release in over 3 years
delegate_it gem provides an easy way to use ActiveSupport like delegate method in your non Rails projects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

#Delegate it Build Status Gem Version Coverage Status

delegate_it gem provides an easy way to use ActiveSupport like delegate method in your non Rails projects.

Installation

In your Gemfile:

gem 'delegate_it'

Usage

require 'delegate_it'

class Cowboy
  extend DelegateIt
  attr_reader :pouch, :pistol

  delegate :name, to: :horse, prefix: true
  delegate :money, to: :pouch, allow_nil: true
  delegate :bullets, to: :pistol, allow_nil: true, prefix: :gun

  def horse
    Struct.new(:name).new('Jolly Jumper')
  end
end

cowboy = Cowboy.new
cowboy.horse_name # => 'Jolly Jumper'
cowboy.money # => nil
cowboy.gun_bullets # => nil

Supported options

allow_nil: true - if the delegate does not exist method call will return nil.

prefix: true - prefix delegated method name with the delegate or custom name.