0.0
No commit activity in last 3 years
No release in over 3 years
Provides Object#thru as an complement to Object#tap
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
< 4.0.0, >= 3.0.0
>= 0.8.0
 Project Readme

ObjectThru

Build Status Test Coverage Code Climate

This is a ruby gem which provides Object#thru as a complement to Ruby's Object#tap. Object#thru comes handy if you are doing lots of chained/functional style programming and you want to return the result of a chained call without the need for temp variables.

Installation

Add this line to your application's Gemfile:

gem 'object_thru'

And then execute:

$ bundle

Or install it yourself as:

$ gem install object_thru

Usage

Object#thru accepts either a block or a callable. If a block is given, the block is called with the object, Object#thru was called on. If called with a callable, the callable is called with the object, Object#thru was called on.

Examples

Using Object#thru with a block

require "object_thru"

[1,2,3]
.map { |integer| integer * 3 }
.reject { |integer| integer <= 9 }
.thru do |array|
  array.length <= 1 ? array.first : array
end
# => 9

Using Object#thru with a callable

require "object_thru"

ensure_integer = -> (object) { object.respond_to?(:to_i) ? object.to_i : 0 }
"123".thru(ensure_integer)
# => 123

Contributing

  1. Fork it ( https://github.com/msievers/object_thru/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request