Skip to content

Commit 8112772

Browse files
authored
Merge pull request #127 from k-tsj/deconstruct_keys
Use deconstruct_keys instead of deconstruct
2 parents f8a0f70 + a126bfb commit 8112772

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/dry/struct.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def inspect
188188
# Pattern matching support
189189
#
190190
# @api private
191-
def deconstruct
192-
[attributes]
191+
def deconstruct_keys(keys)
192+
attributes
193193
end
194194
end
195195
end

spec/dry/struct/pattern_matching_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
context 'pattern matching' do
4444
def match(user)
4545
case user
46-
in User({ first_name: 'Jack' })
46+
in User(first_name: 'Jack')
4747
"It's Jack"
48-
in User({ first_name: 'Alice' | 'Carol' })
48+
in User(first_name: 'Alice' | 'Carol')
4949
'Alice or Carol'
50-
in User({ first_name:, last_name: 'Doe' })
50+
in User(first_name:, last_name: 'Doe')
5151
"DOE, #{first_name.upcase}"
52-
in User({ first_name:, last_name: 'Doe' })
52+
in User(first_name:, last_name: 'Doe')
5353
"DOE, #{first_name.upcase}"
54-
in User({ first_name:, address: Address({ street: 'Downing street' }) })
54+
in User(first_name:, address: Address(street: 'Downing street'))
5555
"PM is #{first_name}"
5656
end
5757
end
@@ -66,14 +66,14 @@ def match(user)
6666

6767
example 'collecting name' do
6868
case john
69-
in User({ address: _, **name })
69+
in User(address: _, **name)
7070
expect(name).to eql(first_name: 'John', last_name: 'Doe')
7171
end
7272
end
7373

7474
example 'multiple structs' do
7575
case john
76-
in User({ first_name: 'John' } | { first_name: 'Jack' })
76+
in User(first_name: 'John' | 'Jack')
7777
end
7878
end
7979
end
@@ -88,7 +88,7 @@ class Operation
8888

8989
def call(result)
9090
case result
91-
in Success(User({ first_name: }))
91+
in Success(User(first_name:))
9292
"Name is #{first_name}"
9393
in Failure[:not_found]
9494
"Wasn't found"

0 commit comments

Comments
 (0)