Project

endeavour

0.0
No commit activity in last 3 years
No release in over 3 years
Try, but better.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Endeavour

Endeavour is a simple gem that adds a try method to Object and NilClass instances. try permits calling a method on an object and returning nil rather than NoMethodError if the object is nil or does not respond to the method.

CircleCI

Usage

There are two ways to use try:

1. Call-based syntax (similar to Rails' Object#try)

car.try(:drive)

colors.try(:[], :red)

1. Delegate syntax (inspired by HoboSupport)

car.try.drive

colors.try[:red]

Installation

Add this line to your application's Gemfile:

gem 'endeavour'

And then execute:

$ bundle

Or install it yourself as:

$ gem install endeavour

Rails applications

Endeavour uses a Railtie and can be used after initialization without additional configuration.

Non-Rails applications

Call Endeavour.hook! early in your application.

Remove Endeavour

In some cases, you may want to remove Endeavour (say, if a naughty gem requires it). You can do so with Endeavour.remove_hook!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/allspiritseve/endeavour.

License

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