mug 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mug.rb +1 -0
- data/lib/mug/enumerable/chain.rb +5 -1
- data/lib/mug/hash/map.rb +6 -0
- data/lib/mug/iterator.rb +1 -1
- data/lib/mug/with.rb +1 -0
- data/test/test-with.rb +46 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4264ea134edd98eb0f3b98b9af1d3d6b201158843f41f1adc24463e17680c0
|
4
|
+
data.tar.gz: 233a5598d2598106cbce6de061c1d3d91e7bee1647f314708c1a2ea812c200d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03571d89948df0dd21c24f1b598a9324f9caac1c53537a45f0853583756ba6a4acdacbb7de4d7b15eec9c549232212b0af9d6620d93205cd4fe726de680498a7
|
7
|
+
data.tar.gz: a945570b56260c0e14c82b46fcc363cbf69925aee08679de9327f9246d9f721a877b14c79c5266905a25145839f688980c83d68adadd9e606274efa19cfb3672
|
data/lib/mug.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative 'mug/array/to_proc'
|
|
11
11
|
require_relative 'mug/bool'
|
12
12
|
require_relative 'mug/bittest'
|
13
13
|
require_relative 'mug/clamp'
|
14
|
+
require_relative 'mug/compat'
|
14
15
|
require_relative 'mug/enumerable/any-and-all'
|
15
16
|
require_relative 'mug/enumerable/chain'
|
16
17
|
require_relative 'mug/enumerable/counts'
|
data/lib/mug/enumerable/chain.rb
CHANGED
@@ -14,7 +14,11 @@ module Enumerable
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
if RUBY_VERSION >= '2.6'
|
18
|
+
warn "warning: Enumerable\#chain defined since Ruby 2.6 is incompatible with this gem when used with args and a block"
|
19
|
+
undef chain
|
20
|
+
end
|
21
|
+
|
18
22
|
#
|
19
23
|
# Creates a chain of Enumerables following this one, and
|
20
24
|
# invokes a block once for each element of each Enumerable.
|
data/lib/mug/hash/map.rb
CHANGED
@@ -8,6 +8,7 @@ class Hash
|
|
8
8
|
# {'a'=>1, 'b'=>2}.map_values { "cat" } #=> {'a'=>"cat", 'b'=>"cat"}
|
9
9
|
#
|
10
10
|
def map_values &_block # :yields: value
|
11
|
+
return enum_for(:map_values) unless block_given?
|
11
12
|
hsh = {}
|
12
13
|
each do |k, v|
|
13
14
|
hsh[k] = yield v
|
@@ -21,6 +22,7 @@ class Hash
|
|
21
22
|
# See: #map_values
|
22
23
|
#
|
23
24
|
def map_values! &block # :yields: value
|
25
|
+
return enum_for(:map_values!) unless block_given?
|
24
26
|
replace map_values(&block)
|
25
27
|
end
|
26
28
|
|
@@ -35,6 +37,7 @@ class Hash
|
|
35
37
|
# {'a'=>1, 'b'=>2}.map_keys { "cat" } #=> {'cat'=>2}
|
36
38
|
#
|
37
39
|
def map_keys &_block # :yields: key
|
40
|
+
return enum_for(:map_keys) unless block_given?
|
38
41
|
hsh = {}
|
39
42
|
each do |k, v|
|
40
43
|
hsh[ yield k ] = v
|
@@ -50,6 +53,7 @@ class Hash
|
|
50
53
|
# See: #map_keys
|
51
54
|
#
|
52
55
|
def map_keys! &block # :yields: key
|
56
|
+
return enum_for(:map_keys!) unless block_given?
|
53
57
|
replace map_keys(&block)
|
54
58
|
end
|
55
59
|
|
@@ -64,6 +68,7 @@ class Hash
|
|
64
68
|
# {'a'=>1, 'b'=>2}.map_pairs { ["cat","dog"] } #=> {'cat'=>'dog'}
|
65
69
|
#
|
66
70
|
def map_pairs &_block # :yields: key, value
|
71
|
+
return enum_for(:map_pairs) unless block_given?
|
67
72
|
hsh = {}
|
68
73
|
each do |k, v|
|
69
74
|
a, b = yield k, v
|
@@ -78,6 +83,7 @@ class Hash
|
|
78
83
|
# See: #map_values
|
79
84
|
#
|
80
85
|
def map_pairs! &block # :yields: key, value
|
86
|
+
return enum_for(:map_pairs!) unless block_given?
|
81
87
|
replace map_pairs(&block)
|
82
88
|
end
|
83
89
|
end
|
data/lib/mug/iterator.rb
CHANGED
@@ -22,7 +22,7 @@ class Iterator < Enumerator
|
|
22
22
|
# In the second, deprecated, form, a generated Iterator sends the
|
23
23
|
# given method with any +args+ to the iterand.
|
24
24
|
#
|
25
|
-
# Use of this form is
|
25
|
+
# Use of this form is discouraged. Use Object#iter_for or
|
26
26
|
# Object#to_iter instead.
|
27
27
|
#
|
28
28
|
# @call-seq new(initial, *args) { |obj, *args| ... }
|
data/lib/mug/with.rb
CHANGED
data/test/test-with.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
class ::DummyClass
|
5
|
+
def self.dummy_method
|
6
|
+
:ok
|
7
|
+
end
|
8
|
+
def self.clobber_method
|
9
|
+
:original
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative '../lib/mug/with'
|
14
|
+
class Test_with < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def test_with
|
17
|
+
input = [1, 'two', :three]
|
18
|
+
output = nil
|
19
|
+
|
20
|
+
with(*input) do |a, b, c|
|
21
|
+
output = [a, b, c]
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal( output, input )
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_with__noblock
|
28
|
+
input = [1, 'two', :three]
|
29
|
+
output = nil
|
30
|
+
|
31
|
+
enum = with(*input)
|
32
|
+
assert_kind_of( Enumerator, enum )
|
33
|
+
|
34
|
+
enum.each do |a, b, c|
|
35
|
+
output = [a, b, c]
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal( output, input )
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_with__private
|
42
|
+
assert_raise(NoMethodError) { self.with }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- test/test-tau.rb
|
107
107
|
- test/test-time.rb
|
108
108
|
- test/test-top.rb
|
109
|
+
- test/test-with.rb
|
109
110
|
homepage: http://phluid61.github.com/mug
|
110
111
|
licenses:
|
111
112
|
- ISC
|
@@ -125,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
- !ruby/object:Gem::Version
|
126
127
|
version: '0'
|
127
128
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.7.6
|
129
|
+
rubygems_version: 3.0.1
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: 'MUG: Matty''s Ultimate Gem'
|
@@ -150,6 +150,7 @@ test_files:
|
|
150
150
|
- test/test-array-to_proc.rb
|
151
151
|
- test/test-affix.rb
|
152
152
|
- test/test-hashmerge.rb
|
153
|
+
- test/test-with.rb
|
153
154
|
- test/test-any-and-all.rb
|
154
155
|
- test/test-self.rb
|
155
156
|
- test/test-enumerable-chain.rb
|