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:
|
right way round:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
thing.in?('Egg', 'Bacon', 'Sausage')
|
thing.in?(['Egg', 'Bacon', 'Sausage'])
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -37,10 +37,14 @@ Require Inny and then start testing your objects:
|
|||||||
```ruby
|
```ruby
|
||||||
require 'inny'
|
require 'inny'
|
||||||
|
|
||||||
object.in?('Foo', 'Bar')
|
object.in?(['Foo', 'Bar'])
|
||||||
|
|
||||||
|
'Foo'.in?('Foobar')
|
||||||
|
|
||||||
|
5.in?(1..10)
|
||||||
|
|
||||||
list = [1, 2, 3]
|
list = [1, 2, 3]
|
||||||
puts "Yay!" if 2.in?(*list)
|
puts "Yay!" if 2.in?(list)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
require "inny/version"
|
require "inny/version"
|
||||||
|
|
||||||
module Inny
|
module Inny
|
||||||
def in?(*list)
|
def in?(object)
|
||||||
list.include?(self)
|
begin
|
||||||
|
object.include?(self)
|
||||||
|
rescue NoMethodError
|
||||||
|
raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
module Inny
|
module Inny
|
||||||
VERSION = "1.0.0"
|
VERSION = "2.0.0"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user