mighty_tap 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/README.md +10 -10
- data/benchmark/mighty_tap.rb +20 -0
- data/lib/mighty_tap/version.rb +1 -1
- data/lib/mighty_tap.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31909c709daaeece2cfddb62d45c748cdf72aa70
|
4
|
+
data.tar.gz: fcc0af96a36ca308f09c48bac7c8eea0dafb3066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a27055f29f5dc3a3eda18f0bed8c4e23c8118f111bd6946ff2986e7effa9166432697eefe798dbe8c7d8fa169bc1fb3a2550ec05fa098bc2274313d3b014694
|
7
|
+
data.tar.gz: 8366a90392665f209b6987a83e6cb2917284a6c0a45027a81a676f7ad8805571f4638cb708eeed859b1f0198b7b4946238c3909729cb2241578412eb8321df29
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
[](https://codeclimate.com/github/msievers/mighty_tap)
|
4
4
|
[](https://codeclimate.com/github/msievers/mighty_tap)
|
5
5
|
|
6
|
-
|
6
|
+
Ruby's `Object#tap` is awesome. mighty_tap tries to make it even better by adding some missing features, while maintaining full compatibility with the original. In order to make its usage more pleasant, `mighty_tap` is defined as an instance method on `Object` and aliased to `Object#mtap`.
|
7
7
|
|
8
8
|
## Why is it even more awesome than `tap` ?
|
9
9
|
* you can give it a method name
|
10
10
|
* you can give it arguments and blocks for methods to call
|
11
|
-
*
|
11
|
+
* despite calling methods on the object itself, you can provide a callable
|
12
12
|
* in fact you can provide anything that responds to :call
|
13
|
-
*
|
13
|
+
* apart from adding features, it acts like the original `tap` (can act as a drop-in replacement)
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
@@ -20,17 +20,17 @@ require "mighty_tap"
|
|
20
20
|
#
|
21
21
|
# it can be used just like tap
|
22
22
|
#
|
23
|
-
[
|
23
|
+
[1,2,3].mtap(&:shift) # => [2,3]
|
24
24
|
|
25
25
|
#
|
26
|
-
#
|
26
|
+
# despite the implicit &: block syntax, it can take a method name
|
27
27
|
#
|
28
|
-
[
|
28
|
+
[1,2,3].mtap(:shift) # => [2,3]
|
29
29
|
|
30
30
|
#
|
31
31
|
# it also takes method arguments
|
32
32
|
#
|
33
|
-
[
|
33
|
+
[1,2,3].mtap(:shift, 2) # => [3]
|
34
34
|
|
35
35
|
#
|
36
36
|
# if the last argument is a proc, the method is called with the procs block variant
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
class ArrayMultiplier
|
55
55
|
def call(array, factor, &reducer)
|
56
56
|
multiplied_array = array.map! { |element| element * factor }
|
57
|
-
|
57
|
+
|
58
58
|
if block_given?
|
59
59
|
yield multiplied_array
|
60
60
|
end
|
@@ -62,10 +62,10 @@ class ArrayMultiplier
|
|
62
62
|
end
|
63
63
|
|
64
64
|
[1,2,3].mtap(ArrayMultiplier.new, 3) # => [3,6,9]
|
65
|
-
[1,2,3].mtap(ArrayMultiplier.new, 3, -> (array) { array.delete_if { |
|
65
|
+
[1,2,3].mtap(ArrayMultiplier.new, 3, -> (array) { array.delete_if { |i| i < 9 } }) # => [9]
|
66
66
|
|
67
67
|
#
|
68
|
-
# this can all be
|
68
|
+
# this can all be combined with taps original block syntax
|
69
69
|
#
|
70
70
|
[1,2,3].mtap(ArrayDoubler.new) do |doubled_array|
|
71
71
|
doubled_array.map! { |element| element * element }
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "benchmark/ips"
|
2
|
+
require "mighty_tap"
|
3
|
+
|
4
|
+
class BenchmarkMightyTap
|
5
|
+
def call
|
6
|
+
array = [1,2,3,4]
|
7
|
+
|
8
|
+
Benchmark.ips do |x|
|
9
|
+
x.report("map!") do
|
10
|
+
array.mtap(:map!) do |_item|
|
11
|
+
_item * 2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
x.compare!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
BenchmarkMightyTap.new.call
|
data/lib/mighty_tap/version.rb
CHANGED
data/lib/mighty_tap.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mighty_tap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Sievers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,10 +81,12 @@ files:
|
|
81
81
|
- ".gitignore"
|
82
82
|
- ".rspec"
|
83
83
|
- ".travis.yml"
|
84
|
+
- CHANGELOG.md
|
84
85
|
- Gemfile
|
85
86
|
- LICENSE.txt
|
86
87
|
- README.md
|
87
88
|
- Rakefile
|
89
|
+
- benchmark/mighty_tap.rb
|
88
90
|
- bin/console
|
89
91
|
- bin/setup
|
90
92
|
- lib/mighty_tap.rb
|