array-tweaks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +24 -0
- data/README.md +31 -0
- data/Rakefile +8 -0
- data/array-tweaks.gemspec +23 -0
- data/lib/array-tweaks.rb +21 -0
- data/lib/array-tweaks/version.rb +6 -0
- data/test/test-array-tweaks.rb +37 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 852d7207cfafe5e39ca5ef22a1692588fe41d1da
|
4
|
+
data.tar.gz: 2d28e8c25866faf62d363e29874cdb724e5b02c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f9229c0cceb09131623da94659324498e6794f92a2a3f9a052677d9c0ad71c132cfe44c5ca262d990709130f4493cc6b596c02591ade4db045b992a70f5455a
|
7
|
+
data.tar.gz: 85d09f4a6ef899d0d7af1e3aa9102c11ea63669f4074d1a02441ddc89dba7a2e0e80d9c4e182fc8375821a1050a31c7d424ff4cbd695dbbdd5de9fbb5ea91649
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
array-tweaks (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
power_assert (1.0.1)
|
10
|
+
rake (12.0.0)
|
11
|
+
test-unit (3.2.3)
|
12
|
+
power_assert
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
array-tweaks!
|
19
|
+
bundler (~> 1.7)
|
20
|
+
rake (~> 12.0)
|
21
|
+
test-unit (~> 3.2)
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
1.14.3
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## Responsibly extends Ruby's Array with simple and predictable utilities.
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/array-tweaks.svg)](https://badge.fury.io/rb/array-tweaks)
|
4
|
+
[![Build Status](https://travis-ci.org/yivo/array-tweaks.svg?branch=master)](https://travis-ci.org/yivo/array-tweaks)
|
5
|
+
|
6
|
+
## Current features
|
7
|
+
* `drop_last`
|
8
|
+
* `drop_last!`
|
9
|
+
* `each_with_index_and_size`
|
10
|
+
|
11
|
+
## Installing gem
|
12
|
+
Add to your Gemfile:
|
13
|
+
```ruby
|
14
|
+
gem 'array-tweaks', '~> 1.0'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Running tests
|
18
|
+
Install bundler:
|
19
|
+
```bash
|
20
|
+
gem install bundler
|
21
|
+
```
|
22
|
+
|
23
|
+
Install dependencies:
|
24
|
+
```bash
|
25
|
+
cd array-tweaks && bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
Run tests:
|
29
|
+
```bash
|
30
|
+
cd array-tweaks && bundle exec rake test
|
31
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require File.expand_path('../lib/array-tweaks/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'array-tweaks'
|
8
|
+
s.version = ArrayTweaks::VERSION
|
9
|
+
s.author = 'Yaroslav Konoplov'
|
10
|
+
s.email = 'eahome00@gmail.com'
|
11
|
+
s.summary = "Responsibly extends Ruby's Array with simple and predictable utilities."
|
12
|
+
s.description = "Responsibly extends Ruby's Array with simple and predictable utilities."
|
13
|
+
s.homepage = 'https://github.com/yivo/array-tweaks'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
22
|
+
s.add_development_dependency 'test-unit', '~> 3.2'
|
23
|
+
end
|
data/lib/array-tweaks.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module ArrayTweaks
|
5
|
+
module Extension
|
6
|
+
def drop_last
|
7
|
+
slice(0, (size - 1).abs) # or slice(0...-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def drop_last!
|
11
|
+
slice!(-1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def each_with_index_and_size
|
15
|
+
size = self.size
|
16
|
+
each_with_index { |item, index| yield(item, index, size) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Array.include ArrayTweaks::Extension
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.require :default, :development, :test
|
6
|
+
|
7
|
+
class ArrayTweaksTest < Test::Unit::TestCase
|
8
|
+
def test_drop_last
|
9
|
+
x = [1,2,3,4]
|
10
|
+
y = x.drop_last
|
11
|
+
assert_equal [1,2,3], y
|
12
|
+
assert_not_same x, y
|
13
|
+
|
14
|
+
x = [1,2,3,4]
|
15
|
+
assert_equal 4, x.drop_last!
|
16
|
+
assert_equal [1,2,3], x
|
17
|
+
assert_same x, x
|
18
|
+
|
19
|
+
x = []
|
20
|
+
assert_equal [], x.drop_last
|
21
|
+
|
22
|
+
x = []
|
23
|
+
assert_nil x.drop_last!
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_each_with_index_and_size
|
27
|
+
x_outer = 1
|
28
|
+
i_outer = 0
|
29
|
+
(1..5).to_a.each_with_index_and_size do |x, i, s|
|
30
|
+
assert_equal x_outer, x
|
31
|
+
assert_equal i_outer, i
|
32
|
+
assert_equal 5, s
|
33
|
+
x_outer += 1
|
34
|
+
i_outer += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array-tweaks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yaroslav Konoplov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Responsibly extends Ruby's Array with simple and predictable utilities.
|
56
|
+
email: eahome00@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".travis.yml"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- array-tweaks.gemspec
|
68
|
+
- lib/array-tweaks.rb
|
69
|
+
- lib/array-tweaks/version.rb
|
70
|
+
- test/test-array-tweaks.rb
|
71
|
+
homepage: https://github.com/yivo/array-tweaks
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.6.8
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Responsibly extends Ruby's Array with simple and predictable utilities.
|
95
|
+
test_files:
|
96
|
+
- test/test-array-tweaks.rb
|