refinements 7.5.0 → 7.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ccd018fc5d5ae2bfa0b6fc1b9f090bc3638ac4053ea5790d7826e2c291bc378
4
- data.tar.gz: 43cd2a8603f9e8667eab9c18aa24ccf5b1f7860054d88b7bc39e22df1bfad573
3
+ metadata.gz: b33464363d548d0cc888f7f3b1efac924eb2490a3846353589d892900d03de0d
4
+ data.tar.gz: da1d401505c092c0b2e8850f476affb1932b79db770b4f11c263300e208f3457
5
5
  SHA512:
6
- metadata.gz: b5dd7fb29e0de7fe1e51209d427889331d8179c5e92868167e818e25dd792509d4221cdf07448a86bea13820cb13ccf0c680cb4b459c7c57ebb0dc0017255aba
7
- data.tar.gz: 94a069d63f4c565fd0c189d489887d23e7420bb63b8a9ec3cb5defc3626a87158037eb7cefdafdaa1b43e5b66764fda59dcf9007279cdcc3d8d53eadbf078bb7
6
+ metadata.gz: 6c8072c3a3d8348e871ed72c7519295fb4ade95e2463bf56424f42689909dc7113805fbc817012196a395442af811f4d215a5bc89cf8952bd4506b0a4cd49536
7
+ data.tar.gz: 7797a5f506eb95d5999234c6e506ef9b0f4b949cfa41f831fcf883425fea7cb3da3b3ff3ef72f5c218236c006c38aeb2a957127ccf5177748fc3cac4291498ba
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -27,6 +27,8 @@ toc::[]
27
27
  ** `#rewrite` - When given a file path and a block, it provides the contents of the recently read
28
28
  file for manipulation and immediate writing back to the same file.
29
29
  * *Hashes*:
30
+ ** `.infinite` - Answers new hash where missing keys, even deeply nested, answer an empty hash.
31
+ ** `.with_default` - Answers new hash where every top-level missing key has the same default value.
30
32
  ** `#except` - Answers new hash with given keys removed without modifying itself.
31
33
  ** `#except!` - Answers new hash with given keys removed while modifying itself.
32
34
  ** `#symbolize_keys` - Converts keys to symbols without modifying itself.
@@ -70,7 +72,7 @@ manipulation and immediate writing back to the same file.
70
72
 
71
73
  == Requirements
72
74
 
73
- . https://www.ruby-lang.org[Ruby 2.7.x].
75
+ . https://www.ruby-lang.org[Ruby].
74
76
  . A solid understanding of link:https://www.alchemists.io/articles/ruby_refinements[Ruby refinements
75
77
  and lexical scope].
76
78
 
@@ -200,6 +202,15 @@ File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
200
202
 
201
203
  [source,ruby]
202
204
  ----
205
+ example = Hash.infinite
206
+ example[:a] # => {}
207
+ example[:a][:b][:c] # => {}
208
+
209
+ example = Hash.with_default ""
210
+ example[:a] # => ""
211
+ example = Hash.with_default []
212
+ example[:b] # => []
213
+
203
214
  example = {a: 1, b: 2, c: 3}
204
215
  example.except :a, :b # => {c: 3}
205
216
  example # => {a: 1, b: 2, c: 3}
@@ -2,6 +2,16 @@
2
2
 
3
3
  module Refinements
4
4
  module Hashes
5
+ refine Hash.singleton_class do
6
+ def infinite
7
+ new { |new_hash, missing_key| new_hash[missing_key] = new(&new_hash.default_proc) }
8
+ end
9
+
10
+ def with_default value
11
+ new { |new_hash, missing_key| new_hash[missing_key] = value }
12
+ end
13
+ end
14
+
5
15
  refine Hash do
6
16
  def except *keys
7
17
  reject { |key, _value| keys.include? key }
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.5.0"
8
+ VERSION = "7.6.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.5.0
4
+ version: 7.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-06-07 00:00:00.000000000 Z
31
+ date: 2020-07-04 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
@@ -50,28 +50,28 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '14.0'
53
+ version: '14.2'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '14.0'
60
+ version: '14.2'
61
61
  - !ruby/object:Gem::Dependency
62
- name: git-cop
62
+ name: git-lint
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '4.0'
67
+ version: '1.0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '4.0'
74
+ version: '1.0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: guard-rspec
77
77
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file