hashmap 0.1.0 → 0.2.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hashmap.rb +104 -75
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c20f904760916de0dcc2353dbee373135432d9ac
4
- data.tar.gz: e4eeb6d7851f489967b7da00ab71adf2c2c004ee
3
+ metadata.gz: b2582690c253d61d1d0157647883cb1e7e019afd
4
+ data.tar.gz: 0aef9b23921cfcdd90dba1a1aebe5d8efd383f72
5
5
  SHA512:
6
- metadata.gz: 08089466608a69e5770cb5b06ded0cda5501cf85dc3b8f160504d378ccc0510b4cfe868fc2b01a657eac9ab2d575c523e03bd3625bff0a181f572a8061b02c8a
7
- data.tar.gz: 1ec74d7f3ea5319cd56a035b63ef4140817fc4e6c8250f732b7295dc6dedb16dd67b9726d5a2ff6f9ccbd574a72e245b15c6d7f70780d78f9cb26c7ab45c148a
6
+ metadata.gz: e6d6f8ac18d9a9189868c67f44bc8d045e973668f511178946769e359004eda17dd9e2949656b67dd1f4a91348a9202f8ec078e84d67465508e53c1c7d19b9ec
7
+ data.tar.gz: 8e22f67962881997485d48850f929f7a1f8b4e3192b3b0441434182287c79e6ea1dec2417ece098f55c7148f7efca6f70669d0c75bf56ebf343fd3db3e294ed5
@@ -1,83 +1,112 @@
1
+
1
2
  class Hash
2
- #
3
- # Returns a new hash which is a copy of the current hash but each
4
- # value is replaced by the result of running it through +block+.
5
- #
6
- # {'a'=>1, 'b'=>2}.map_values { |v| v*2 } #=> {'a'=>2, 'b'=>4}
7
- # {'a'=>1, 'b'=>2}.map_values { "cat" } #=> {'a'=>"cat", 'b'=>"cat"}
8
- #
9
- def map_values &block # :yields: value
10
- hsh = {}
11
- each do |k, v|
12
- hsh[k] = yield v
13
- end
14
- hsh
15
- end
3
+ #
4
+ # Returns a new hash which is a copy of the current hash but each
5
+ # value is replaced by the result of running it through +block+.
6
+ #
7
+ # {'a'=>1, 'b'=>2}.map_values { |v| v*2 } #=> {'a'=>2, 'b'=>4}
8
+ # {'a'=>1, 'b'=>2}.map_values { "cat" } #=> {'a'=>"cat", 'b'=>"cat"}
9
+ #
10
+ # If no block is given, an Enumerator is returned instead.
11
+ #
12
+ def map_values &block # :yields: value
13
+ return enum_for(:map_values) unless block_given?
14
+ hsh = {}
15
+ each do |k, v|
16
+ hsh[k] = yield v
17
+ end
18
+ hsh
19
+ end
16
20
 
17
- #
18
- # Replaces the values in +hsh+ by running them each through +block+.
19
- #
20
- # See: #map_values
21
- #
22
- def map_values! &block # :yields: value
23
- replace map_values(&block)
24
- end
21
+ #
22
+ # Replaces the values in +hsh+ by running them each through +block+.
23
+ #
24
+ # See: #map_values
25
+ #
26
+ def map_values! &block # :yields: value
27
+ return enum_for(:map_values!) unless block_given?
28
+ replace map_values(&block)
29
+ end
25
30
 
26
- #
27
- # Returns a new hash which is a copy of the current hash but each
28
- # key is replaced by the result of running it through +block+.
29
- #
30
- # If +block+ returns duplicate keys, they will be overwritten in
31
- # the resulting hash.
32
- #
33
- # {'a'=>1, 'b'=>2}.map_keys { |k| k*2 } #=> {'aa'=>1, 'bb'=>2}
34
- # {'a'=>1, 'b'=>2}.map_keys { "cat" } #=> {'cat'=>2}
35
- #
36
- def map_keys &block # :yields: key
37
- hsh = {}
38
- each do |k, v|
39
- hsh[ yield k ] = v
40
- end
41
- hsh
42
- end
31
+ #
32
+ # Returns a new hash which is a copy of the current hash but each
33
+ # key is replaced by the result of running it through +block+.
34
+ #
35
+ # If +block+ returns duplicate keys, they will be overwritten in
36
+ # the resulting hash.
37
+ #
38
+ # {'a'=>1, 'b'=>2}.map_keys { |k| k*2 } #=> {'aa'=>1, 'bb'=>2}
39
+ # {'a'=>1, 'b'=>2}.map_keys { "cat" } #=> {'cat'=>2}
40
+ #
41
+ # If no block is given, an Enumerator is returned instead.
42
+ #
43
+ def map_keys &block # :yields: key
44
+ return enum_for(:map_keys) unless block_given?
45
+ hsh = {}
46
+ each do |k, v|
47
+ hsh[ yield k ] = v
48
+ end
49
+ hsh
50
+ end
43
51
 
44
- #
45
- # Replaces the keys in +hsh+ by running them each through +block+.
46
- #
47
- # If +block+ returns duplicate keys, they will be overwritten in turn.
48
- #
49
- # See: #map_keys
50
- #
51
- def map_keys! &block # :yields: key
52
- replace map_keys(&block)
53
- end
52
+ #
53
+ # Replaces the keys in +hsh+ by running them each through +block+.
54
+ #
55
+ # If +block+ returns duplicate keys, they will be overwritten in turn.
56
+ #
57
+ # See: #map_keys
58
+ #
59
+ def map_keys! &block # :yields: key
60
+ return enum_for(:map_keys!) unless block_given?
61
+ replace map_keys(&block)
62
+ end
54
63
 
55
- #
56
- # Returns a new hash which is a copy of the current hash but each
57
- # key-value pair is replaced by the result of running it through +block+.
58
- #
59
- # If +block+ returns duplicate keys, they will be overwritten in
60
- # the resulting hash.
61
- #
62
- # {'a'=>1, 'b'=>2}.map_pairs { |k,v| [k*2, v+1] } #=> {'aa'=>2, 'bb'=>3}
63
- # {'a'=>1, 'b'=>2}.map_pairs { ["cat","dog"] } #=> {'cat'=>'dog'}
64
- #
65
- def map_pairs &block # :yields: key, value
66
- hsh = {}
67
- each do |k, v|
68
- a, b = yield k, v
69
- hsh[a] = b
70
- end
71
- hsh
72
- end
64
+ #
65
+ # Returns a new hash which is a copy of the current hash but each
66
+ # key-value pair is replaced by the result of running it through +block+.
67
+ #
68
+ # If +block+ returns duplicate keys, they will be overwritten in
69
+ # the resulting hash.
70
+ #
71
+ # {'a'=>1, 'b'=>2}.map_pairs { |k,v| [k*2, v+1] } #=> {'aa'=>2, 'bb'=>3}
72
+ # {'a'=>1, 'b'=>2}.map_pairs { ["cat","dog"] } #=> {'cat'=>'dog'}
73
+ #
74
+ # If no block is given, an Enumerator is returned instead.
75
+ #
76
+ def map_pairs &block # :yields: key, value
77
+ return enum_for(:map_pairs) unless block_given?
78
+ hsh = {}
79
+ each do |k, v|
80
+ a, b = yield k, v
81
+ hsh[a] = b
82
+ end
83
+ hsh
84
+ end
73
85
 
74
- #
75
- # Replaces the values in +hsh+ by running them each through +block+.
76
- #
77
- # See: #map_values
78
- #
79
- def map_pairs! &block # :yields: key, value
80
- replace map_pairs(&block)
81
- end
86
+ #
87
+ # Replaces the values in +hsh+ by running them each through +block+.
88
+ #
89
+ # See: #map_pairs
90
+ #
91
+ def map_pairs! &block # :yields: key, value
92
+ return enum_for(:map_pairs!) unless block_given?
93
+ replace map_pairs(&block)
94
+ end
82
95
  end
83
96
 
97
+ =begin
98
+ Copyright (c) 2013-2016, Matthew Kerwin <matthew@kerwin.net.au>
99
+
100
+ Permission to use, copy, modify, and/or distribute this software for any
101
+ purpose with or without fee is hereby granted, provided that the above
102
+ copyright notice and this permission notice appear in all copies.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
105
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
106
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
107
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
108
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
109
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
110
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
111
+ =end
112
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-13 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Defines some new mapping methods for Hash. See https://bugs.ruby-lang.org/issues/7793
14
14
  email: matthew@kerwin.net.au
@@ -19,7 +19,7 @@ files:
19
19
  - lib/hashmap.rb
20
20
  homepage: http://rubygems.org/gems/hashmap
21
21
  licenses:
22
- - Simplified BSD License
22
+ - ISC
23
23
  metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options: []
@@ -27,17 +27,17 @@ require_paths:
27
27
  - lib
28
28
  required_ruby_version: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.0.0
40
+ rubygems_version: 2.5.1
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: New mappings for Hash