pluckit 1.3.0 → 1.3.1
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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +14 -0
- data/lib/pluckit/pluck.rb +6 -2
- data/lib/pluckit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c607d3a501e2f5bf3a971dc37b53a3088b2f009f4d9d47fbbbca030339de63f
|
|
4
|
+
data.tar.gz: 7f02ef863a371794cade093a6323f08782d493ae6142157b4fdc008b340b173e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 434128cd7cf59df1c0ae996b810ba5741775ea0a680a5b7e81d08c663353da3e53975d468fccc2a9e223de3212b9abb72a0d5d7ad9d5843684a6228642338f49
|
|
7
|
+
data.tar.gz: 6acdad5f4a933a5e53464904938172f09820af22ddf5af057dc66a22bc25805ec74bc78b315efe8c5aedc0833ae73b51475c19ab448fbdc553c2f1c4238977ef
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### 1.3.1 (2026-11-03)
|
|
2
|
+
- fix: `PluckIt.pluck` on other Enumerables (Range, Enumerator, lazy) returns an Array (or a lazy enumerator) instead of raising NoMethodError
|
|
3
|
+
- fix: `PluckIt.pluck` on a frozen Array, Hash, or Set returns a new result instead of raising FrozenError
|
|
4
|
+
|
|
1
5
|
### 1.3.0 (2026-11-03)
|
|
2
6
|
- drop Ruby 3.0 and 3.1 (end of life); requires Ruby >= 3.2
|
|
3
7
|
- feature: a callable handle (lambda, proc, Method) is called with each value: `users.pluck(->(u) { u.name.upcase })`
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -40,3 +40,17 @@ require 'pluckit'
|
|
|
40
40
|
[ 'alice', 'bob' ].pluck ->(name) { name.capitalize }
|
|
41
41
|
=> [ 'Alice', 'Bob' ]
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#### Without the monkey patch
|
|
46
|
+
`require 'pluckit'` adds `#pluck` to Array, Hash, and Set. To skip the global patch, load the module alone and use the refinement, or call it directly:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
require 'pluckit/pluck'
|
|
50
|
+
|
|
51
|
+
using PluckIt
|
|
52
|
+
[ { id: 1 } ].pluck :id
|
|
53
|
+
|
|
54
|
+
# or
|
|
55
|
+
PluckIt.pluck [ { id: 1 } ], :id
|
|
56
|
+
```
|
data/lib/pluckit/pluck.rb
CHANGED
|
@@ -20,10 +20,14 @@ module PluckIt
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def pluck enumerable, *handles
|
|
23
|
+
# these keep their type (and subclass) via dup.clear; anything else maps
|
|
24
|
+
unless [ Array, Hash, Set ].any? { |klass| enumerable.is_a?(klass) }
|
|
25
|
+
return enumerable.map { |val| pluckit(val, *handles) }
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
items = enumerable.each_with_object(
|
|
24
|
-
enumerable.
|
|
29
|
+
enumerable.dup.clear # dup, not clone: clone keeps frozen and singleton methods
|
|
25
30
|
)
|
|
26
|
-
# TODO: if no clone / clear, use new
|
|
27
31
|
|
|
28
32
|
if enumerable.is_a?(Hash)
|
|
29
33
|
items.each do |(key, val), res|
|
data/lib/pluckit/version.rb
CHANGED