Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timrogers/object-in
A monkeypatch on Ruby's Object which adds the instance method "in?", which is Array#include? with the subject and object inverted
https://github.com/timrogers/object-in
Last synced: 28 days ago
JSON representation
A monkeypatch on Ruby's Object which adds the instance method "in?", which is Array#include? with the subject and object inverted
- Host: GitHub
- URL: https://github.com/timrogers/object-in
- Owner: timrogers
- License: unlicense
- Created: 2013-03-30T17:26:21.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-03-30T17:29:41.000Z (almost 12 years ago)
- Last Synced: 2024-12-25T05:47:23.737Z (about 1 month ago)
- Language: Ruby
- Size: 109 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Object#in?
A monkeypatch on Object which adds the instance method `in?`, which is
effectively the standard library `Array#include?` method with the subject
and object inverted i.e. so the object you're search for receives the method
call.## Installation
Add this line to your application's Gemfile:
gem 'object-in'
And then execute:
$ bundle
Or install it yourself as:
$ gem install object-in
You can view me on Rubygems.org [here](http://rubygems.org/gems/object-in).
## Usage
This adds to Object, so it will be available on *(essentially?)* everything.
It takes one parameter, the array you want to check for the object's inclusion
in.```ruby
array = %w{yankee doodle doo}
"yankee".in? array # => true
"da".in? array # => false
yankee.in? array.join(" ") # => raises a TypeError exception
```* It returns true if the array passed in includes the object.
* It returns false if the array passed in doesn't include the object.
* It raises a TypeError exception if the passed in object isn't an Array## Contributing
1. Fork it
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 new Pull Request