everythingrb 0.8.1 → 0.8.2
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 +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +7 -3
- data/lib/everythingrb/hash.rb +7 -0
- data/lib/everythingrb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1dea4517af697abde3f07ffb40d62a7ec40b3f8c0b91cc74eb93edde92e5aac
|
4
|
+
data.tar.gz: bb3888fac39b4d3138ddfb5f7d36504d3df28c274b4d9a950772aca0c5d5f0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 341bf18d8e774f882b01b5ab50a7d262d113ecdbefab288c4e373cc6bb89b9f86a3ddf8a67d7a842016e6f62d04816db136c658106cf11685c50bd7d35693264
|
7
|
+
data.tar.gz: d7d3f73c40cec2555958de71452af51945f681d7e9731edc477c6428e316e71c607e22d00abd9257a1b4dd6ee0be0ee33b067a745c996593109621251464c8ea
|
data/CHANGELOG.md
CHANGED
@@ -15,6 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
15
15
|
### Removed
|
16
16
|
-->
|
17
17
|
|
18
|
+
## [0.8.2] - 12025-05-25
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Fixed `Hash#rename_key_unordered` and `Hash#rename_key_unordered!` to not create new key-value pairs when the original key doesn't exist. Previously, these methods would incorrectly add the `new_key` to the hash even when `old_key` was missing.
|
25
|
+
|
26
|
+
### Removed
|
27
|
+
|
18
28
|
## [0.8.1] - 12025-05-21
|
19
29
|
|
20
30
|
### Added
|
@@ -291,7 +301,8 @@ This change aligns our method signatures with Ruby's conventions and matches our
|
|
291
301
|
|
292
302
|
- Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
|
293
303
|
|
294
|
-
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.8.
|
304
|
+
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.8.2...HEAD
|
305
|
+
[0.8.2]: https://github.com/itsthedevman/everythingrb/compare/v0.8.1...v0.8.2
|
295
306
|
[0.8.1]: https://github.com/itsthedevman/everythingrb/compare/v0.8.0...v0.8.1
|
296
307
|
[0.8.0]: https://github.com/itsthedevman/everythingrb/compare/v0.7.0...v0.8.0
|
297
308
|
[0.7.0]: https://github.com/itsthedevman/everythingrb/compare/v0.6.1...v0.7.0
|
data/README.md
CHANGED
@@ -12,11 +12,15 @@ We've all been there - writing the same tedious patterns over and over:
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
# BEFORE
|
15
|
-
users = [
|
15
|
+
users = [
|
16
|
+
{ name: "Alice", role: "admin" },
|
17
|
+
{ name: "Bob", role: "user" },
|
18
|
+
{ name: "Charlie", role: "admin" }
|
19
|
+
]
|
16
20
|
admin_users = users.select { |u| u[:role] == "admin" }
|
17
21
|
admin_names = admin_users.map { |u| u[:name] }
|
18
22
|
result = admin_names.join(", ")
|
19
|
-
# => "Alice"
|
23
|
+
# => "Alice, Charlie"
|
20
24
|
```
|
21
25
|
|
22
26
|
With EverythingRB, you can write code that actually says what you mean:
|
@@ -24,7 +28,7 @@ With EverythingRB, you can write code that actually says what you mean:
|
|
24
28
|
```ruby
|
25
29
|
# AFTER
|
26
30
|
users.join_map(", ") { |u| u[:name] if u[:role] == "admin" }
|
27
|
-
# => "Alice"
|
31
|
+
# => "Alice, Charlie"
|
28
32
|
```
|
29
33
|
|
30
34
|
*Methods used: [`join_map`](https://itsthedevman.com/docs/everythingrb/Array.html#join_map-instance_method)*
|
data/lib/everythingrb/hash.rb
CHANGED
@@ -629,6 +629,10 @@ class Hash
|
|
629
629
|
# But as the hash becomes larger, the performance improvements become diminished until they're roughly the same.
|
630
630
|
# Neat!
|
631
631
|
hash = except(old_key)
|
632
|
+
|
633
|
+
# Only modify the hash if the old key exists
|
634
|
+
return hash unless key?(old_key)
|
635
|
+
|
632
636
|
hash[new_key] = self[old_key]
|
633
637
|
hash
|
634
638
|
end
|
@@ -650,6 +654,9 @@ class Hash
|
|
650
654
|
# # => {a: 1, c: 3, middle: 2} # Order may differ
|
651
655
|
#
|
652
656
|
def rename_key_unordered!(old_key, new_key)
|
657
|
+
# Only modify the hash if the old key exists
|
658
|
+
return self unless key?(old_key)
|
659
|
+
|
653
660
|
self[new_key] = delete(old_key)
|
654
661
|
self
|
655
662
|
end
|
data/lib/everythingrb/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ostruct
|