mirror of
https://github.com/danbee/inny
synced 2025-03-04 08:59:10 +00:00
Match syntax to ActiveSupport in? method
This commit is contained in:
parent
70c44927c1
commit
04539b69be
10
README.md
10
README.md
@ -11,7 +11,7 @@ I'd much rather ask an object if it was in a list. It just feels like it's the
|
||||
right way round:
|
||||
|
||||
```ruby
|
||||
thing.in?('Egg', 'Bacon', 'Sausage')
|
||||
thing.in?(['Egg', 'Bacon', 'Sausage'])
|
||||
```
|
||||
|
||||
## Installation
|
||||
@ -37,10 +37,14 @@ Require Inny and then start testing your objects:
|
||||
```ruby
|
||||
require 'inny'
|
||||
|
||||
object.in?('Foo', 'Bar')
|
||||
object.in?(['Foo', 'Bar'])
|
||||
|
||||
'Foo'.in?('Foobar')
|
||||
|
||||
5.in?(1..10)
|
||||
|
||||
list = [1, 2, 3]
|
||||
puts "Yay!" if 2.in?(*list)
|
||||
puts "Yay!" if 2.in?(list)
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
require "inny/version"
|
||||
|
||||
module Inny
|
||||
def in?(*list)
|
||||
list.include?(self)
|
||||
def in?(object)
|
||||
begin
|
||||
object.include?(self)
|
||||
rescue NoMethodError
|
||||
raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
module Inny
|
||||
VERSION = "1.0.0"
|
||||
VERSION = "2.0.0"
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user