mirror of
https://github.com/danbee/inny
synced 2025-03-04 08:59:10 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3565a65051 | |||
|
|
7b120879e1 | ||
|
|
6b9e118895 | ||
|
|
04539b69be | ||
| 70c44927c1 | |||
| 95730e957e |
13
README.md
13
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,7 +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)
|
||||
```
|
||||
|
||||
## Development
|
||||
@ -48,7 +55,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/inny. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/danbee/inny. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
4
Rakefile
4
Rakefile
@ -4,7 +4,7 @@ require "rake/testtask"
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << "test"
|
||||
t.libs << "lib"
|
||||
t.test_files = FileList['test/**/*_test.rb']
|
||||
t.test_files = FileList["test/**/*_test.rb"]
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
||||
18
inny.gemspec
18
inny.gemspec
@ -1,7 +1,7 @@
|
||||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
lib = File.expand_path("../lib", __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'inny/version'
|
||||
require "inny/version"
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "inny"
|
||||
@ -9,25 +9,27 @@ Gem::Specification.new do |spec|
|
||||
spec.authors = ["Dan Barber"]
|
||||
spec.email = ["github@danbarber.me"]
|
||||
|
||||
spec.summary = %q{Better syntax for testing whether an object is in a list}
|
||||
spec.description = %q{Better syntax for testing whether an object is in a list}
|
||||
spec.summary = "Better syntax for testing whether an object is in a list"
|
||||
spec.description = "Better syntax for testing whether an object is in a list"
|
||||
spec.homepage = "https://github.com/danbee/inny"
|
||||
spec.license = "MIT"
|
||||
|
||||
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
||||
# delete this section to allow pushing this gem to any host.
|
||||
if spec.respond_to?(:metadata)
|
||||
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
||||
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
||||
else
|
||||
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
||||
end
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
spec.files =
|
||||
`git ls-files -z`.split("\x0")
|
||||
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.10"
|
||||
spec.add_development_dependency "rake", "~> 10.0"
|
||||
spec.add_development_dependency "bundler", "~> 2.4"
|
||||
spec.add_development_dependency "rake", "~> 13.0"
|
||||
spec.add_development_dependency "minitest"
|
||||
end
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
require "inny/version"
|
||||
|
||||
module Inny
|
||||
def in?(*list)
|
||||
list.include?(self)
|
||||
def in?(object)
|
||||
object.include?(self)
|
||||
rescue NoMethodError
|
||||
raise ArgumentError.new(
|
||||
"The parameter passed to #in? must respond to #include?"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
module Inny
|
||||
VERSION = "1.0.0"
|
||||
VERSION = "3.0.0"
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
require 'test_helper'
|
||||
require "test_helper"
|
||||
|
||||
class InnyTest < Minitest::Test
|
||||
def test_that_it_has_a_version_number
|
||||
@ -6,19 +6,24 @@ class InnyTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_it_finds_integers
|
||||
assert 8.in?(1, 2, 3) == false
|
||||
assert 8.in?(7, 8, 9) == true
|
||||
assert 8.in?([7, 8, 9])
|
||||
refute 8.in?([1, 2, 3])
|
||||
end
|
||||
|
||||
def test_it_finds_strings
|
||||
assert 'Egg'.in?('Apple', 'Orange', 'Banana') == false
|
||||
assert 'Egg'.in?('Bacon', 'Sausage', 'Egg') == true
|
||||
assert "Egg".in?(%w[Bacon Sausage Egg])
|
||||
refute "Egg".in?(%w[Apple Orange Banana])
|
||||
end
|
||||
|
||||
def test_it_finds_substrings
|
||||
assert "bar".in?("Foobar")
|
||||
refute "egg".in?("Foobar")
|
||||
end
|
||||
|
||||
def test_it_finds_things_in_an_array
|
||||
list = ['John', 'Jimmy', 'Robert']
|
||||
list = %w[John Jimmy Robert]
|
||||
|
||||
assert 'John Paul'.in?(*list) == false
|
||||
assert 'Jimmy'.in?(*list) == true
|
||||
assert "Jimmy".in?(list)
|
||||
refute "John Paul".in?(list)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
||||
require 'inny'
|
||||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
||||
require "inny"
|
||||
|
||||
require 'minitest/autorun'
|
||||
require "minitest/autorun"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user