Skip to content

Commit b6c2fa0

Browse files
committed
Implemented is_array?
0 parents  commit b6c2fa0

14 files changed

+233
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: ruby
2+
rvm:
3+
- 2.3.0
4+
before_install: gem install bundler -v 1.11.2

CODE_OF_CONDUCT.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of
4+
fostering an open and welcoming community, we pledge to respect all people who
5+
contribute through reporting issues, posting feature requests, updating
6+
documentation, submitting pull requests or patches, and other activities.
7+
8+
We are committed to making participation in this project a harassment-free
9+
experience for everyone, regardless of level of experience, gender, gender
10+
identity and expression, sexual orientation, disability, personal appearance,
11+
body size, race, ethnicity, age, religion, or nationality.
12+
13+
Examples of unacceptable behavior by participants include:
14+
15+
* The use of sexualized language or imagery
16+
* Personal attacks
17+
* Trolling or insulting/derogatory comments
18+
* Public or private harassment
19+
* Publishing other's private information, such as physical or electronic
20+
addresses, without explicit permission
21+
* Other unethical or unprofessional conduct
22+
23+
Project maintainers have the right and responsibility to remove, edit, or
24+
reject comments, commits, code, wiki edits, issues, and other contributions
25+
that are not aligned to this Code of Conduct, or to ban temporarily or
26+
permanently any contributor for other behaviors that they deem inappropriate,
27+
threatening, offensive, or harmful.
28+
29+
By adopting this Code of Conduct, project maintainers commit themselves to
30+
fairly and consistently applying these principles to every aspect of managing
31+
this project. Project maintainers who do not follow or enforce the Code of
32+
Conduct may be permanently removed from the project team.
33+
34+
This code of conduct applies both within project spaces and in public spaces
35+
when an individual is representing the project or its community.
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
38+
reported by contacting a project maintainer at [email protected]. All
39+
complaints will be reviewed and investigated and will result in a response that
40+
is deemed necessary and appropriate to the circumstances. Maintainers are
41+
obligated to maintain confidentiality with regard to the reporter of an
42+
incident.
43+
44+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45+
version 1.3.0, available at
46+
[http://contributor-covenant.org/version/1/3/0/][version]
47+
48+
[homepage]: http://contributor-covenant.org
49+
[version]: http://contributor-covenant.org/version/1/3/0/

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in is_array.gemspec
4+
gemspec

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Dan Garland
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# IsArray
2+
3+
Inspired by the NodeJS isArray package, https://www.npmjs.com/package/isarray
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'is_array'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install is_array
20+
21+
## Usage
22+
23+
```
24+
is_array?(%w(apple pear banana))
25+
=> true
26+
27+
is_array?("Anything else")
28+
=> false
29+
```
30+
31+
## Development
32+
33+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34+
35+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36+
37+
## Thanks
38+
39+
Thanks to David Haney for excellent blog post on dependency management in nodejs
40+
http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/
41+
42+
Thanks also to Phil Nash for pointing out the lack of gems in the Ruby ecosystem
43+
at Bath Ruby 2016.
44+
45+
## Contributing
46+
47+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/is_array. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48+
49+
50+
## License
51+
52+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new(:test) do |t|
5+
t.libs << "test"
6+
t.libs << "lib"
7+
t.test_files = FileList['test/**/*_test.rb']
8+
end
9+
10+
task :default => :spec

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "is_array"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

is_array.gemspec

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'is_array/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "is_array"
8+
spec.version = IsArray::VERSION
9+
spec.authors = ["Dan Garland"]
10+
spec.email = ["[email protected]"]
11+
12+
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13+
spec.description = %q{TODO: Write a longer description or delete this line.}
14+
spec.homepage = "TODO: Put your gem's website or public repo URL here."
15+
spec.license = "MIT"
16+
17+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18+
# delete this section to allow pushing this gem to any host.
19+
if spec.respond_to?(:metadata)
20+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21+
else
22+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23+
end
24+
25+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26+
spec.bindir = "exe"
27+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28+
spec.require_paths = ["lib"]
29+
30+
spec.add_development_dependency "bundler", "~> 1.11"
31+
spec.add_development_dependency "rake", "~> 10.0"
32+
spec.add_development_dependency "minitest", "~> 5.0"
33+
end

lib/is_array.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "is_array/version"
2+
3+
def is_array?(object)
4+
object.is_a? Array
5+
end

lib/is_array/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module IsArray
2+
VERSION = "1.0.0"
3+
end

test/is_array_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'test_helper'
2+
3+
class IsArrayTest < Minitest::Test
4+
def test_that_it_has_a_version_number
5+
refute_nil ::IsArray::VERSION
6+
end
7+
8+
def test_is_array_returns_true_when_given_an_array
9+
assert_equal true, is_array?([])
10+
end
11+
12+
def test_is_array_returns_false_for_anything_else
13+
assert_equal false, is_array?(nil)
14+
assert_equal false, is_array?(5)
15+
assert_equal false, is_array?(Object.new)
16+
end
17+
end

test/test_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2+
require 'is_array'
3+
4+
require 'minitest/autorun'

0 commit comments

Comments
 (0)