brasic / enumerable-only

Provides Enumerable#only, which raises if more than one item could be returned

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enumerable::Only

Adds the #only method to all Enumerable objects.

#only behaves like first, except that it raises if more than one item is in the collection.

# no items in the collection:

[].only => nil


# exactly one item in the collection:

[:item].only => :item

# more than one items in the collection:

[:first, :second].only => raises TooManyItems

Installation

Add this line to your application's Gemfile:

gem 'enumerable-only'

And then execute:

$ bundle

Or install it yourself as:

$ gem install enumerable-only

License

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

About

Provides Enumerable#only, which raises if more than one item could be returned

License:MIT License


Languages

Language:Ruby 96.8%Language:Shell 3.2%