everythingrb 0.4.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfa8c1ad4940f61e609e0b70618493a050979540beb9e3388828d9c8741f9103
4
- data.tar.gz: a4851a664e888577d68a01fc9830d9d8c812ff5758edce994eacd0f1440887f4
3
+ metadata.gz: 320458b0c0e09c8556129b456eb191ff588a6b2277b5da46a5273dc36c4f3a50
4
+ data.tar.gz: 824f8c91fbe4749022a8a5f2caf6d6f76714a6d7faf747a4f25818342d5d5b39
5
5
  SHA512:
6
- metadata.gz: dd750b905857c86db3cdd8c054c50a7900e2ef194fdd51df69bd35267f0f947bbb93dca3df9bb7596758b15a5312203cb02875ff99c90eca03aab7d63c064e79
7
- data.tar.gz: 6c9c6198b3ef913c4cfebcae52cc85573a499a29b4d21eb2826e22f13dfd58f20fa96333faa92a3ff2d7e88ad38df97247d1836b7b554eb859e59dcd17f03bd2
6
+ metadata.gz: ac7ed45151941a1e124372ebfb1394fb8176f4703bc903fa634d3672a251c8a4e497f8555bc1433848512d7e8edb04926c8a043420d3337041c7fc00e9e7eebd
7
+ data.tar.gz: b0d711b08f5ec75aa07ab009587784a926f2e5832a35037da89a96fa5d800a29e4e4b1c3beb81ba6b86b3d5821252aeda2ab2f124234f859af477cbeb186a8cb
data/CHANGELOG.md CHANGED
@@ -23,7 +23,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
23
 
24
24
  ### Removed
25
25
 
26
- ## [0.4.0]
26
+ ## [0.5.0] - 12025-04-17
27
+
28
+ **BREAKING:**
29
+
30
+ The parameter order in `Hash#transform_values.with_key` has been changed to yield `|value, key|` instead of `|key, value|` to maintain consistency with Ruby's standard enumeration methods like `each_with_index`.
31
+
32
+ **Before:**
33
+ ```ruby
34
+ hash.transform_values.with_key { |key, value| "#{key}: #{value}" }
35
+ ```
36
+
37
+ **After:**
38
+ ```ruby
39
+ hash.transform_values.with_key { |value, key| "#{key}: #{value}" }
40
+ ```
41
+
42
+ This change aligns our method signatures with Ruby's conventions and matches our other methods like `join_map(with_index: true)` which yields `|value, index|`.
43
+
44
+ ### Added
45
+
46
+ - Added `Hash#transform` and `Hash#transform!` for transforming a hash's keys and values at the same time.
47
+
48
+ ### Changed
49
+ - Changed parameter order in `Hash#transform_values.with_key` to yield `|value, key|` instead of `|key, value|` for consistency with Ruby conventions.
50
+
51
+ ### Removed
52
+
53
+
54
+ ## [0.4.0] - 12025-04-11
27
55
 
28
56
  ### Added
29
57
 
@@ -170,7 +198,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
170
198
 
171
199
  - Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
172
200
 
173
- [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.4.0...HEAD
201
+ [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.5.0...HEAD
202
+ [0.5.0]: https://github.com/itsthedevman/everythingrb/compare/v0.4.0...v0.5.0
174
203
  [0.4.0]: https://github.com/itsthedevman/everythingrb/compare/v0.3.1...v0.4.0
175
204
  [0.3.1]: https://github.com/itsthedevman/everythingrb/compare/v0.3.0...v0.3.1
176
205
  [0.3.0]: https://github.com/itsthedevman/everythingrb/compare/v0.2.5...v0.3.0
@@ -8,6 +8,7 @@
8
8
  # - #join_map: Combine filter_map and join operations
9
9
  # - #deep_freeze: Recursively freeze hash and contents
10
10
  # - #transform_values.with_key: Transform values with access to keys
11
+ # - #transform, #transform!: Transform keys and values
11
12
  # - #value_where, #values_where: Find values based on conditions
12
13
  # - #rename_key, #rename_keys: Rename hash keys while preserving order
13
14
  # - ::new_nested_hash: Create automatically nesting hashes
@@ -274,7 +275,7 @@ class Hash
274
275
  # # => {a: 2, b: 4}
275
276
  #
276
277
  # @example Using with_key to access keys during transformation
277
- # {a: 1, b: 2}.transform_values.with_key { |k, v| "#{k}_#{v}" }
278
+ # {a: 1, b: 2}.transform_values.with_key { |v, k| "#{k}_#{v}" }
278
279
  # # => {a: "a_1", b: "b_2"}
279
280
  #
280
281
  def transform_values(&block)
@@ -304,7 +305,7 @@ class Hash
304
305
  #
305
306
  # @example Using with_key to access keys during in-place transformation
306
307
  # hash = {a: 1, b: 2}
307
- # hash.transform_values!.with_key { |k, v| "#{k}_#{v}" }
308
+ # hash.transform_values!.with_key { |v, k| "#{k}_#{v}" }
308
309
  # # => {a: "a_1", b: "b_2"}
309
310
  #
310
311
  def transform_values!(&block)
@@ -313,6 +314,49 @@ class Hash
313
314
  og_transform_values!(&block)
314
315
  end
315
316
 
317
+ #
318
+ # Transforms keys and values to create a new hash
319
+ #
320
+ # @yield [key, value] Block that returns a new key-value pair
321
+ # @yieldparam key [Object] The original key
322
+ # @yieldparam value [Object] The original value
323
+ # @yieldreturn [Array] Two-element array containing the new key and value
324
+ #
325
+ # @return [Hash] A new hash with transformed keys and values
326
+ # @return [Enumerator] If no block is given
327
+ #
328
+ # @example Transform both keys and values
329
+ # {a: 1, b: 2}.transform { |k, v| ["#{k}_key", v * 2] }
330
+ # # => {a_key: 2, b_key: 4}
331
+ #
332
+ def transform(&block)
333
+ return to_enum(:transform) if block.nil?
334
+
335
+ to_h(&block)
336
+ end
337
+
338
+ #
339
+ # Transforms keys and values in place
340
+ #
341
+ # @yield [key, value] Block that returns a new key-value pair
342
+ # @yieldparam key [Object] The original key
343
+ # @yieldparam value [Object] The original value
344
+ # @yieldreturn [Array] Two-element array containing the new key and value
345
+ #
346
+ # @return [self] The transformed hash
347
+ # @return [Enumerator] If no block is given
348
+ #
349
+ # @example Transform both keys and values in place
350
+ # hash = {a: 1, b: 2}
351
+ # hash.transform! { |k, v| ["#{k}_key", v * 2] }
352
+ # # => {a_key: 2, b_key: 4}
353
+ #
354
+ def transform!(&block)
355
+ return to_enum(:transform!) if block.nil?
356
+
357
+ replace(transform(&block))
358
+ end
359
+
316
360
  #
317
361
  # Returns the first value where the key-value pair satisfies the given condition
318
362
  #
@@ -496,7 +540,7 @@ class Hash
496
540
  raise ArgumentError, "Missing block for Hash#transform_values.with_key" if block.nil?
497
541
 
498
542
  original_hash.each_pair.with_object({}) do |(key, value), output|
499
- output[key] = block.call(key, value)
543
+ output[key] = block.call(value, key)
500
544
  end
501
545
  end
502
546
 
@@ -512,7 +556,7 @@ class Hash
512
556
  raise ArgumentError, "Missing block for Hash#transform_values!.with_key" if block.nil?
513
557
 
514
558
  original_hash.each_pair do |key, value|
515
- original_hash[key] = block.call(key, value)
559
+ original_hash[key] = block.call(value, key)
516
560
  end
517
561
 
518
562
  original_hash
@@ -7,5 +7,5 @@
7
7
  #
8
8
  module Everythingrb
9
9
  # Current version of the everythingrb gem
10
- VERSION = "0.4.0"
10
+ VERSION = "0.5.0"
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everythingrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-12 00:00:00.000000000 Z
11
+ date: 2025-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ostruct