1
0
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:
Dan Barber 2015-09-24 11:55:34 +01:00
parent 70c44927c1
commit 04539b69be
3 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,3 @@
module Inny module Inny
VERSION = "1.0.0" VERSION = "2.0.0"
end end