with_ease 0.0.2 → 0.0.3

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: 1acaa86f823eeec13d846b6af27f39e94ec5bffa9d19fa81ce78994680efbfa5
4
- data.tar.gz: 2c23c88589ed075d3289e27528e9d8ceb1acda6eeee0a45e6c21cae6a95240ef
3
+ metadata.gz: 44fc03afd4f77bdedbf359da249bb22cf3c80f9eef3f3cd7e24f90287a88536e
4
+ data.tar.gz: 0002a8ed601d3a61917efdfee29ffe7c2a17b48a476bd3e832c85c42c0b242f7
5
5
  SHA512:
6
- metadata.gz: a6cb7b523b7481b4696242a2addd533cd08c158f6652e8e8ab11b2aa6cbeb262abfbde383a14ad51e3dda8013ff45ba431901fdcd075636aaf48d73c10aac6f8
7
- data.tar.gz: 2f5c8b59bf12285100c0cabf7a592a55117a8b6c0e0e9d946141d14c76290c24c2770a8bc519210ac4b58cf3bf7c5b45a73292d570aec7e6f79d97a87f46937e
6
+ metadata.gz: b5c2c94c3f0610529fcdb0b570bbd44a19ca6cc9c0fbcbf9b0a0ed27263c21adf30b1c7c6509bcdc633e2bb893c2f900eae5a09bc9b3011c98a075067999c232
7
+ data.tar.gz: 1f283686e92f306c47b13f94394ad359779342f7d31f4aa7deff37d323ba22bc2ce07d01c88ec423d14657141c894a53a9c25f89d52a11198e5e13ecafe71766
@@ -6,5 +6,5 @@ require_relative 'open_struct'
6
6
 
7
7
  def ClosedStruct(**k) = WithEase::ClosedStruct.new(**k)
8
8
  def Iterator(init, &blk) = WithEase::Iterator.new(init, &blk)
9
- def OpenStruct(**k) = WithEase::OpenStruct.new(**k)
9
+ def OpenStruct(**k) = OpenStruct.new(**k)
10
10
  # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -16,15 +16,18 @@ module WithEase
16
16
  end
17
17
  end
18
18
 
19
- def update(hash_like=nil, **keys, &blk)
19
+ def update(*positionals, **keys, &blk)
20
20
  if blk
21
- return _update_with_blk(hash_like, **keys, &blk)
21
+ return _update_with_blk(*positionals, **keys, &blk)
22
22
  end
23
23
 
24
- if hash_like
24
+ case positionals
25
+ in []
26
+ _update(keys)
27
+ in [hash_like]
25
28
  _update(hash_like.to_h.merge(**keys))
26
29
  else
27
- _update(keys)
30
+ raise ArgumentError, "must not provide more than one postional argument"
28
31
  end
29
32
  end
30
33
 
@@ -47,10 +50,23 @@ module WithEase
47
50
  self
48
51
  end
49
52
 
50
- def _update_with_blk(key, **keys, &blk)
51
- raise ArgumentError, "no **keys arguments allowed in block form" unless keys.empty?
52
- value = fetch(key)
53
- _update(key => blk.(value))
53
+ def _update_with_blk(*positionals, **keys, &blk)
54
+ case positionals
55
+ in []
56
+ new_hash = to_h.update(**keys, &blk)
57
+ _update(new_hash)
58
+ in [key]
59
+ if keys.has_key?(:default)
60
+ value = fetch(key, keys.delete(:default))
61
+ raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
62
+ _update(key => blk.(value))
63
+ else
64
+ value = fetch(key)
65
+ raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
66
+ _update(key => blk.(value))
67
+ end
68
+ in [_, _, *]
69
+ end
54
70
  end
55
71
  end
56
72
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WithEase
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  # SPDX-License-Identifier: AGPL-3.0-or-later
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_ease
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober