diff --git a/README.md b/README.md index db60791..c82e7a6 100644 --- a/README.md +++ b/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 diff --git a/lib/inny.rb b/lib/inny.rb index ef3c41e..b4fdd70 100644 --- a/lib/inny.rb +++ b/lib/inny.rb @@ -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 diff --git a/lib/inny/version.rb b/lib/inny/version.rb index 0596b70..00a63fe 100644 --- a/lib/inny/version.rb +++ b/lib/inny/version.rb @@ -1,3 +1,3 @@ module Inny - VERSION = "1.0.0" + VERSION = "2.0.0" end