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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b5b9c9186972f16733b08421a3797b465556d35
4
- data.tar.gz: 144cb66da27377e6270266a4f26c85bca3d14485
3
+ metadata.gz: 31909c709daaeece2cfddb62d45c748cdf72aa70
4
+ data.tar.gz: fcc0af96a36ca308f09c48bac7c8eea0dafb3066
5
5
  SHA512:
6
- metadata.gz: ad354b1c1d492487a6d43608d60101abecccc8e834df1bc47c261b61e1d512e318b0edbe71e617884e32510f93beeb9cf5c107e75e154b0d73c7b379a92a5dbb
7
- data.tar.gz: 35b55fd6bca83c619ce7af271c610bd356e8aa408c9857b633075efb31b8fe601fe01bda861cde79b8239f157d81851cf80a881f331aba6a80718b23a728168b
6
+ metadata.gz: 3a27055f29f5dc3a3eda18f0bed8c4e23c8118f111bd6946ff2986e7effa9166432697eefe798dbe8c7d8fa169bc1fb3a2550ec05fa098bc2274313d3b014694
7
+ data.tar.gz: 8366a90392665f209b6987a83e6cb2917284a6c0a45027a81a676f7ad8805571f4638cb708eeed859b1f0198b7b4946238c3909729cb2241578412eb8321df29
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.4.1
2
+
3
+ * Increased performance by removing unnecessary &block argument
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  if !ENV["CI"] && RUBY_ENGINE == "ruby"
7
7
  group :development do
8
+ gem "benchmark-ips"
8
9
  gem "pry", "~> 0.9.12.6"
9
10
  gem "pry-byebug", "<= 1.3.2"
10
11
  gem "pry-rescue", "~> 1.4.1"
data/README.md CHANGED
@@ -3,14 +3,14 @@
3
3
  [![Test Coverage](https://codeclimate.com/github/msievers/mighty_tap/badges/coverage.svg)](https://codeclimate.com/github/msievers/mighty_tap)
4
4
  [![Code Climate](https://codeclimate.com/github/msievers/mighty_tap/badges/gpa.svg)](https://codeclimate.com/github/msievers/mighty_tap)
5
5
 
6
- Rubys `Object#tap` is a awesome. mighty_tap tries to make it even more awesome by adding some missing features, while maintining full compatibility to the orginal `tap`. In order to make its usage more pleasant, `mighty_tap` is defined as in instance method on `Object` and aliased to `mtap`.
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
- * dispite calling methods on the object itself, you can provide a callable
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
- * dispite the added features, it acts like the original `tap` (can act as a drop-in replacement)
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
- [[[1,2,3]]].mtap(&:flatten!) # => [1,2,3]
23
+ [1,2,3].mtap(&:shift) # => [2,3]
24
24
 
25
25
  #
26
- # dispite the implicite &: block syntax, it can take a method name
26
+ # despite the implicit &: block syntax, it can take a method name
27
27
  #
28
- [[[1,2,3]]].mtap(:flatten!) # => [1,2,3]
28
+ [1,2,3].mtap(:shift) # => [2,3]
29
29
 
30
30
  #
31
31
  # it also takes method arguments
32
32
  #
33
- [[[1,2,3]]].mtap(:flatten!, 1) # => [[1,2,3]]
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 { |int| int < 9 } }) # => [9]
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 combinded with taps original block syntax
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
@@ -1,3 +1,3 @@
1
1
  module MightyTap
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/mighty_tap.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "mighty_tap/version"
2
2
 
3
3
  class Object
4
- def mighty_tap(*args, &block)
4
+ def mighty_tap(*args)
5
5
  if args.length > 1 && args.last.is_a?(Proc)
6
6
  method_block_proc = args.pop
7
7
  end
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.0
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-04-10 00:00:00.000000000 Z
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