Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Pattern Matching

Ruby Pattern Matching

Pattern matching is a great way to build Command Line Interfaces (CLIs), deal with third-party Application Programming Interfaces (APIs), and much more. In this presentation you'll learn what pattern matching is and how to leverage the power of pattern matching within your own Ruby applications!

E0e036f89c14b3e59640318eedf9670b?s=128

Brooke Kuhlmann

April 28, 2021
Tweet

Transcript

  1. Ruby Pattern Matching Presented by Brooke Kuhlmann

  2. Ruby 2.7.0 https://rubyreferences.github.io/rubychanges

  3. Ruby 2.7.0 Warning[:experimental] = false https://rubyreferences.github.io/rubychanges

  4. Ruby 2.7.0 Warning[:experimental] = false https://rubyreferences.github.io/rubychanges Ruby 3.0.0 🎉 🎉

  5. https://en.wikipedia.org/wiki/Pattern_matching What

  6. https://en.wikipedia.org/wiki/Pattern_matching What Patterns are a sequence of tokens or tree

    structures which constituents some pattern.
  7. https://en.wikipedia.org/wiki/Pattern_matching What

  8. https://en.wikipedia.org/wiki/Pattern_matching What { ship: "Serenity" , crew: [ { name:

    "Malcolm Reynolds" , title: "Captain" } , { name: "Zoe Alleyne Washburne" , title: "Fighter" } , { name: "Kaywinnet Lee Frye" title: "Engineer" } ] }
  9. https://en.wikipedia.org/wiki/Pattern_matching What { ship: "Serenity" , crew: [ { name:

    "Malcolm Reynolds" , title: "Captain" } , { name: "Zoe Alleyne Washburne" , title: "Fighter" } , { name: "Kaywinnet Lee Frye" title: "Engineer" } ] }
  10. https://en.wikipedia.org/wiki/Pattern_matching What { ship: "Serenity" , crew: [ { name:

    "Malcolm Reynolds" , title: "Captain" } , { name: "Zoe Alleyne Washburne" , title: "Fighter" } , { name: "Kaywinnet Lee Frye" title: "Engineer" } ] }
  11. https://en.wikipedia.org/wiki/Pattern_matching What { ship: "Serenity" , crew: [ { name:

    "Malcolm Reynolds" , title: "Captain" } , { name: "Zoe Alleyne Washburne" , title: "Fighter" } , { name: "Kaywinnet Lee Frye" title: "Engineer" } ] }
  12. https://en.wikipedia.org/wiki/Pattern_matching What { ship: "Serenity" , crew: [ { name:

    "Malcolm Reynolds" , title: "Captain" } , { name: "Zoe Alleyne Washburne" , title: "Fighter" } , { name: "Kaywinnet Lee Frye" title: "Engineer" } ] }
  13. https://en.wikipedia.org/wiki/Pattern_matching Alternatives

  14. https://en.wikipedia.org/wiki/Pattern_matching Alternatives Conditional Logic if..else...elsif...end case...when...else...end

  15. https://en.wikipedia.org/wiki/Pattern_matching Alternatives Regular Expressions Conditional Logic if..else...elsif...end case...when...else...end /[0-9a-z]{32}/

  16. https://en.wikipedia.org/wiki/Pattern_matching Alternatives Regular Expressions Parsers Conditional Logic if..else...elsif...end case...when...else...end /[0-9a-z]{32}/

    Ripper Parser
  17. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview

  18. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives The Joy of Pattern Matching!
  19. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in The Joy of Pattern Matching!
  20. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] The Joy of Pattern Matching!
  21. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} The Joy of Pattern Matching!
  22. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder The Joy of Pattern Matching!
  23. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * The Joy of Pattern Matching!
  24. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * **nil The Joy of Pattern Matching!
  25. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * **nil ^variable The Joy of Pattern Matching!
  26. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * **nil ^variable | The Joy of Pattern Matching!
  27. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * **nil ^variable | if, unless The Joy of Pattern Matching!
  28. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Overview • Standalone • Arrays • Hashes • Remainders

    • Finds • Void • Variable Binding • Combinations • Guard Clauses • Non-Primitives =>, in [<pattern>, <pattern>] {key: <pattern>, key: <pattern>} _, *, *remainder, **, **remainder * **nil ^variable | if, unless desconstruct, desconstruct_keys The Joy of Pattern Matching!
  29. Syntax: Standalone https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  30. Syntax: Standalone https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental

  31. Syntax: Standalone <expression> in <pattern> https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html <expression> => <pattern>

  32. Syntax: Standalone <expression> in <pattern> https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html <expression> => <pattern> ⚠

    Experimental
  33. Syntax: Standalone <expression> in <pattern> https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html <expression> => <pattern> 💡

    True || False ⚠ Experimental
  34. Syntax: Standalone <expression> in <pattern> https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html <expression> => <pattern> 💡

    True || False 💡 Assignment ⚠ Experimental
  35. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Standalone (=>)

  36. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>)
  37. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>) Hash
  38. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>) Pattern
  39. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>)
  40. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>)
  41. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (=>)
  42. {character: {first_name: "Malcolm", last_name: "Reynolds"}} => {character: {last_name:} } puts

    "Last Name: #{last_name}" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Last Name: Reynolds Syntax: Standalone (=>)
  43. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Standalone (in)

  44. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  45. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  46. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  47. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  48. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  49. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental Syntax: Standalone (in)
  50. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental true Syntax: Standalone (in)
  51. basket = [{kind: "apple", quantity: 1}, {kind: "peach", quantity: 5}

    ] basket.any? { |fruit| fruit in {kind: /app/} } https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Experimental true Syntax: Standalone (in) 🚫 ✅
  52. Syntax: Case

  53. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case case <expression> in <pattern> then ... in

    <pattern> then ... in <pattern> then ... else ... end
  54. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case case <expression> in <pattern> then ... in

    <pattern> then ... in <pattern> then ... else ... end
  55. case <expression> in <pattern> then ... when <pattern> then ...

    else ... end https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case
  56. case <expression> in <pattern> then ... when <pattern> then ...

    else ... end https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case
  57. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case

  58. c ccc c cc c c c c ccccc e

    ee https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Syntax: Case (Exhaustive Matching)
  59. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html NoMatchingPatternError Syntax: Case (Exhaustive Matching)

  60. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html NoMatchingPatternError ♥ Syntax: Case (Exhaustive Matching)

  61. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html NoMatchingPatternError ♥ Syntax: Case (Exhaustive Matching)

  62. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Control Flow Pattern Matching Syntax: Case (Exhaustive Matching)

  63. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case <expression> when <pattern> then ... when <pattern> then

    ... when <pattern> then ... end case <expression> in <pattern> then ... in <pattern> then ... in <pattern> then ... end Control Flow Pattern Matching Syntax: Case (Exhaustive Matching)
  64. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case <expression> when <pattern> then ... when <pattern> then

    ... when <pattern> then ... end case <expression> in <pattern> then ... in <pattern> then ... in <pattern> then ... end Control Flow Pattern Matching Nothing Happens 😢 Syntax: Case (Exhaustive Matching)
  65. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case <expression> when <pattern> then ... when <pattern> then

    ... when <pattern> then ... end case <expression> in <pattern> then ... in <pattern> then ... in <pattern> then ... end Control Flow Pattern Matching Nothing Happens 😢 NoMatchingPatternError 🎉 Syntax: Case (Exhaustive Matching)
  66. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case <expression> when <pattern> then ... when <pattern> then

    ... when <pattern> then ... end case <expression> in <pattern> then ... in <pattern> then ... in <pattern> then ... end Control Flow Pattern Matching Syntax: Case (Exhaustive Matching)
  67. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case <expression> when <pattern> then ... when <pattern> then

    ... when <pattern> then ... end case <expression> in <pattern> then ... in <pattern> then ... in <pattern> then ... end Control Flow Pattern Matching Style/MissingElse: Enabled: true Syntax: Case (Exhaustive Matching)
  68. Primitives

  69. [ ] { } Struct Primitives

  70. Syntax: Optional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  71. case [1, 2, 3 ] in [Integer, Integer] then "match"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in {a: Integer} then "matched" else "unmatched" end Syntax: Optional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  72. case [1, 2, 3 ] in Integer, Integer then "match"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" end Syntax: Optional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  73. case [1, 2, 3 ] in Integer, Integer then "match"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" end Syntax: Optional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  74. case [1, 2, 3 ] in Integer, Integer then "match"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" end Syntax: Optional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Required for standalone syntax
  75. Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  76. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  77. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d "unmatched" Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  78. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d "unmatched" Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  79. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d "unmatched" Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html 💡 Order Matters
  80. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d "unmatched" "matched" Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  81. case [1, 2, 3 ] in Integer, Integer then "matched"

    else "unmatched" end case {a: 1, b: 2, c: 3 } in a: Integer then "matched" else "unmatched" en d "unmatched" "matched" Array Hash Whole Versus Partial Matches https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  82. Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  83. case {a: 1, b: 2, c: 3 } in {}

    then "matched" else "unmatched" en d case { } in {} then "matched" else "unmatched" end With Content Without Content Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  84. case {a: 1, b: 2, c: 3 } in {}

    then "matched" else "unmatched" en d case { } in {} then "matched" else "unmatched" end With Content Without Content Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  85. case {a: 1, b: 2, c: 3 } in {}

    then "matched" else "unmatched" en d case { } in {} then "matched" else "unmatched" end "unmatched" With Content Without Content Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  86. case {a: 1, b: 2, c: 3 } in {}

    then "matched" else "unmatched" en d case { } in {} then "matched" else "unmatched" end "unmatched" With Content Without Content Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  87. case {a: 1, b: 2, c: 3 } in {}

    then "matched" else "unmatched" en d case { } in {} then "matched" else "unmatched" end "unmatched" "matched" With Content Without Content Caveat: Empty Hashes https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  88. Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  89. case [:a, 1, :b, :c, 2 ] in *, Symbol,

    Symbol, * then "matched" else "unmatched" end Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  90. case [:a, 1, :b, :c, 2 ] in *, Symbol,

    Symbol, * then "matched" else "unmatched" end Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  91. case [:a, 1, :b, :c, 2 ] in *, Symbol,

    Symbol, * then "matched" else "unmatched" end Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  92. case [:a, 1, :b, :c, 2 ] in *, Symbol,

    Symbol, * then "matched" else "unmatched" end "matched" Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  93. case [:a, 1, :b, :c, 2 ] in *, Symbol,

    Symbol, * then "matched" else "unmatched" end "matched" Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive
  94. ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive

  95. case [:a, 1, :b, :c, 2 ] in *first, Symbol,

    Symbol, *last then {first: first, last: last } else "unmatched" end Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive
  96. case [:a, 1, :b, :c, 2 ] in *first, Symbol,

    Symbol, *last then {first: first, last: last } else "unmatched" end Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive
  97. case [:a, 1, :b, :c, 2 ] in *first, Symbol,

    Symbol, *last then {first: first, last: last } else "unmatched" end { fi rst: [:a, 1], last: [2]} Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive
  98. case [:a, 1, :b, :c, 2 ] in *first, Symbol,

    Symbol, *last then {first: first, last: last } else "unmatched" end { fi rst: [:a, 1], last: [2]} Arrays Only ⚠ Experimental Finds https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html ⚠ Expensive
  99. Voids https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  100. case {a: 1, b: 2 } in {a: Integer, **nil}

    then %(matched "a" part) in {a: Integer, b: Integer, **nil} then "matched whole hash" else "unmatched" end Hashes Only Voids https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  101. case {a: 1, b: 2 } in {a: Integer, **nil}

    then %(matched "a" part) in {a: Integer, b: Integer, **nil} then "matched whole hash" else "unmatched" end "matched whole hash" Hashes Only Voids https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  102. case {a: 1, b: 2 } in {a: Integer, **nil}

    then %(matched "a" part) in {a: Integer, b: Integer, **nil} then "matched whole hash" else "unmatched" end "matched whole hash" Hashes Only Voids https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  103. case {a: 1, b: 2 } in {a: Integer, **nil}

    then %(matched "a" part) in {a: Integer, b: Integer, **nil} then "matched whole hash" else "unmatched" end "matched whole hash" Hashes Only ⚠ Pattern end only Voids https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  104. case {a: 1, b: 2 } in {a: Integer, **nil}

    then %(matched "a" part) in {a: Integer, b: Integer, **nil} then "matched whole hash" else "unmatched" end "matched whole hash" Hashes Only Voids ✅ https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  105. Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  106. case [1, 2, 3 ] in Integer, * then "matched"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in a: Integer, ** then "matched" else "unmatched" end Array Hash Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  107. case [1, 2, 3 ] in Integer, * then "matched"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in a: Integer, ** then "matched" else "unmatched" end Array Hash Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  108. case [1, 2, 3 ] in Integer, * then "matched"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in a: Integer, ** then "matched" else "unmatched" end "matched" Array Hash Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  109. case [1, 2, 3 ] in Integer, * then "matched"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in a: Integer, ** then "matched" else "unmatched" end "matched" Array Hash Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  110. case [1, 2, 3 ] in Integer, * then "matched"

    else "unmatched" en d case {a: 1, b: 2, c: 3 } in a: Integer, ** then "matched" else "unmatched" end "matched" "matched" Array Hash Remainders https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  111. Variable Binding https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  112. case [1, 2 ] in Integer => first, Integer then

    "matched: #{first}" else "unmatched" end case {a: 1, b: 2 } in a: Integer => first then "matched: #{first}" else "unmatched" end Array Variable Binding Hash https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  113. case [1, 2 ] in Integer => first, Integer then

    "matched: #{first}" else "unmatched" end case {a: 1, b: 2 } in a: Integer => first then "matched: #{first}" else "unmatched" end Array Variable Binding Hash https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  114. case [1, 2 ] in Integer => first, Integer then

    "matched: #{first}" else "unmatched" end case {a: 1, b: 2 } in a: Integer => first then "matched: #{first}" else "unmatched" end "matched: 1" Array Variable Binding Hash https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  115. case [1, 2 ] in Integer => first, Integer then

    "matched: #{first}" else "unmatched" end case {a: 1, b: 2 } in a: Integer => first then "matched: #{first}" else "unmatched" end "matched: 1" Array Variable Binding Hash https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  116. case [1, 2 ] in Integer => first, Integer then

    "matched: #{first}" else "unmatched" end case {a: 1, b: 2 } in a: Integer => first then "matched: #{first}" else "unmatched" end "matched: 1" "matched: 1" Array Variable Binding Hash https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  117. Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  118. case [1, 2 ] in first, Integer then "matched: #{first}"

    else "unmatched" end case {a: 1, b: 2 } in a: first then "matched: #{first}" else "unmatched" end Array Hash Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  119. case [1, 2 ] in first, Integer then "matched: #{first}"

    else "unmatched" end case {a: 1, b: 2 } in a: first then "matched: #{first}" else "unmatched" end Array Hash Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  120. case [1, 2 ] in first, Integer then "matched: #{first}"

    else "unmatched" end case {a: 1, b: 2 } in a: first then "matched: #{first}" else "unmatched" end "matched: 1" Array Hash Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  121. case [1, 2 ] in first, Integer then "matched: #{first}"

    else "unmatched" end case {a: 1, b: 2 } in a: first then "matched: #{first}" else "unmatched" end "matched: 1" Array Hash Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  122. case [1, 2 ] in first, Integer then "matched: #{first}"

    else "unmatched" end case {a: 1, b: 2 } in a: first then "matched: #{first}" else "unmatched" end "matched: 1" "matched: 1" Array Hash Variable Binding: Simpli fi ed https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  123. Variable Binding: Hash Only https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  124. case {a: 1, b: 2 } in a: then "matched:

    #{a}" else "unmatched" end Variable Binding: Hash Only https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  125. case {a: 1, b: 2 } in a: then "matched:

    #{a}" else "unmatched" end Variable Binding: Hash Only https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  126. case {a: 1, b: 2 } in a: then "matched:

    #{a}" else "unmatched" end "matched: 1" Variable Binding: Hash Only https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  127. Explicit Brackets Variable Binding: Nested https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  128. case [%w[Apple Apricot], %w[Blueberry Blackberry] ] in [[first, String], *]

    then "matched: #{first}" else "unmatched" end case {label: "Basket", fruits: [{label: "Apple"}, {label: "Peach"}] } in label:, fruits: [{label: first}, *] then "matched: #{first}" else "unmatched" end Array Hash Explicit Brackets Variable Binding: Nested https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  129. case [%w[Apple Apricot], %w[Blueberry Blackberry] ] in [[first, String], *]

    then "matched: #{first}" else "unmatched" end case {label: "Basket", fruits: [{label: "Apple"}, {label: "Peach"}] } in label:, fruits: [{label: first}, *] then "matched: #{first}" else "unmatched" end Array Hash Explicit Brackets Variable Binding: Nested https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  130. case [%w[Apple Apricot], %w[Blueberry Blackberry] ] in [[first, String], *]

    then "matched: #{first}" else "unmatched" end case {label: "Basket", fruits: [{label: "Apple"}, {label: "Peach"}] } in label:, fruits: [{label: first}, *] then "matched: #{first}" else "unmatched" end "matched: Apple" "matched: Apple" Array Hash Explicit Brackets Variable Binding: Nested https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  131. Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  132. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  133. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  134. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  135. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end "matched: 1, [2, 3]" Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  136. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end "matched: 1, [2, 3]" Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  137. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end "matched: 1, [2, 3]" Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  138. case [1, 2, 3 ] in first, *remainder then "matched:

    #{first}, #{remainder}" else "unmatched" end case {a: 1, b: 2, c: 3 } in a:, **remainder then "matched: #{a}, #{remainder}" else "unmatched" end "matched: 1, {:b=>2, :c=>3}" "matched: 1, [2, 3]" Array Hash Variable Binding: Remainder https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  139. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  140. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case [:a, 1, 2.0 ] in

    Symbol | Symbol, Integer, Float then "matched" else "unmatched" end case {a: 1, b: 2, c: 3 } in {a: Integer} | Array then "matched" else "unmatched" end Array Hash
  141. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case [:a, 1, 2.0 ] in

    Symbol | Symbol, Integer, Float then "matched" else "unmatched" end case {a: 1, b: 2, c: 3 } in {a: Integer} | Array then "matched" else "unmatched" end Array Hash
  142. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case [:a, 1, 2.0 ] in

    Symbol | Symbol, Integer, Float then "matched" else "unmatched" end case {a: 1, b: 2, c: 3 } in {a: Integer} | Array then "matched" else "unmatched" end "matched" Array Hash
  143. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case [:a, 1, 2.0 ] in

    Symbol | Symbol, Integer, Float then "matched" else "unmatched" end case {a: 1, b: 2, c: 3 } in {a: Integer} | Array then "matched" else "unmatched" end "matched" "matched" Array Hash
  144. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  145. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end
  146. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end illegal variable in alternative pattern (a) (SyntaxError) Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end 🚫
  147. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end illegal variable in alternative pattern (a) (SyntaxError) Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end 🚫
  148. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end illegal variable in alternative pattern (a) (SyntaxError) Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end matched 🚫 🚫
  149. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end illegal variable in alternative pattern (a) (SyntaxError) Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end matched 🚫 🚫
  150. Variable Binding: Conditional https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case {a: 1, b: 2, c:

    3 } in {a:} | Array then "matched" else "unmatched" end illegal variable in alternative pattern (a) (SyntaxError) Hash Only case {a: 1, b: 2, c: 3 } in {a: _} | Array then "matched" else "unmatched" end matched 🚫 🚫 Meant to signify discarded values only!
  151. Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  152. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  153. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  154. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  155. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  156. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end "matched: 1" Variable Pinning https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  157. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end "matched: 1" Variable Pinning `expectation` is pinned to `1` https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  158. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end "matched: 1" "unmatched: 5" Variable Pinning `expectation` is pinned to `1` https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  159. expectation = 5 case [1, 2 ] in expectation, *remainder

    then "matched: #{expectation}" else "unmatched: #{expectation}" end expectation = 5 case [1, 2 ] in ^expectation, *remainder then "matched: #{expectation}" else "unmatched: #{expectation}" end "matched: 1" "unmatched: 5" Variable Pinning `expectation` is pinned to `1` `expectation` is pinned to `5` https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  160. Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  161. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  162. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  163. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" "values are different" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  164. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" "values are different" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html 1
  165. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" "values are different" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html 1 1
  166. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" "values are different" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html 1 1
  167. case [1, 1 ] in value, ^value then "values are

    identical" else "values are different" end case [1, 2 ] in value, ^value then "values are identical" else "values are different" end "values are identical" "values are different" Variable Pinning: Comparison https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html 1 1 1 1
  168. Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  169. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  170. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  171. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" Key Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  172. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" Pin Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  173. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" Value Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  174. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" Value Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  175. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" ✅ Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  176. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" "unmatched" Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  177. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" "unmatched" Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  178. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" "unmatched" Pin ("high") Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  179. case {school: "high", schools: [{id: 1, level: "middle"}, {id: 2,

    level: "high"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end case {school: "high", schools: [{id: 1, level: "middle"}] } in school:, schools: [*, {id:, level: ^school}] then "matched: #{id}" else "unmatched" end "matched: 2" "unmatched" Pin ("high") "middle" != "high" Variable Pinning: Multiples https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
  180. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  181. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end Array Hash
  182. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end "matched" "matched" Array Hash
  183. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end "matched" "matched" Array Hash
  184. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end "matched" "matched" Array Hash 💡`unless` works too!
  185. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end "matched" "matched" Array Hash 💡`unless` works too!
  186. Guard Clauses https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html case %w[apple peach blueberry ] in String,

    middle, String if middle == "peach" then "matched" else "unmatched" end case {animal: "bat", vehicle: "tumbler", color: "black" } in color: String if color == "black" then "matched" else "unmatched" end "matched" "matched" Array Hash 💡`unless` works too!
  187. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Non-Primitives

  188. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end Non-Primitives
  189. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end Array Non-Primitives
  190. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end Array Hash Non-Primitives
  191. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end Array Pattern Non-Primitives
  192. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end # => "matched: 1" Array Pattern Non-Primitives
  193. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end # => "matched: 1" Array Pattern Non-Primitives
  194. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end # => "matched: 1" case Point.new 1, -2 in x: 0.. => x then "matched: #{x}" else "unmatched" end Array Pattern Hash Pattern Non-Primitives
  195. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end # => "matched: 1" case Point.new 1, -2 in x: 0.. => x then "matched: #{x}" else "unmatched" end # => "matched: 1" Array Pattern Hash Pattern Non-Primitives
  196. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html class Point attr_reader :x, :y def initialize x, y

    @x = x @y = y end def deconstruct = [x, y] def deconstruct_keys(keys) = {x: x, y: y} end case Point.new 1, -2 in x, Integer then "matched: #{x}" else "unmatched" end # => "matched: 1" case Point.new 1, -2 in x: 0.. => x then "matched: #{x}" else "unmatched" end # => "matched: 1" Array Pattern Hash Pattern Non-Primitives
  197. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs

  198. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y

  199. case Point[1, 2 ] in Point[..5, ..5] then "matched" else

    "unmatched" end https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  200. case Point[1, 2 ] in Point[..5, ..5] then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  201. case Point[1, 2 ] in Point[..5, ..5] then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y Same Type
  202. case Point[1, 2 ] in Point[..5, ..5] then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y Point(..5, ..5)
  203. case Point[1, 2 ] in Point[..5, ..5] then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y Point(..5, ..5) Constant(pattern)
  204. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  205. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y "matched"
  206. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y "matched" Same Type
  207. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case [1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y "matched"
  208. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case [1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y "matched" "unmatched"
  209. case Point[1, 2 ] in ..5, ..5 then "matched" else

    "unmatched" end case [1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end case Point[1, 2 ] in Point[..5, ..5] then "matched" else "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y Wrong Type "matched" "unmatched"
  210. https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y

  211. case Point[1, 2 ] in Point(x:, y:) then "matched" else

    "unmatched" end https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  212. case Point[1, 2 ] in Point(x:, y:) then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  213. case Point[1, 2 ] in Point(x:, y:) then "matched" else

    "unmatched" end "matched" https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html Structs Point = Struct.new :x, :y
  214. https://www.alchemists.io

  215. Examples https://www.alchemists.io

  216. https://www.alchemists.io/projects/rubysmith

  217. Rubysmith https://www.alchemists.io/projects/rubysmith

  218. https://www.alchemists.io/projects/rubysmith Rubysmith

  219. https://www.alchemists.io/projects/rubysmith Rubysmith

  220. https://www.alchemists.io/projects/rubysmith Rubysmith

  221. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  222. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  223. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  224. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  225. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  226. https://www.alchemists.io/projects/rubysmith module Rubysmit h module CL I class Shel l

    # Truncated. def call arguments = [ ] # Truncated. case option s in config: action then process_config actio n in build_minimum: true then process_build :build_minimum, option s in build: then process_build :build_maximum, option s in version: then puts version in help: then usag e else usag e end end private # Truncated. def process_config(action) = processors.fetch(:config).call actio n def process_build kind, setting s processors.fetch(kind).call settings.transform_keys(build: :project_name ) .merge(now: Time.now ) end def options = parser.to_ h def usage = puts(parser.to_s ) end end end Rubysmith
  227. None
  228. Deployer

  229. Deployer (Internal)

  230. Deployer (Internal) 🎉 Open Sourced (future)

  231. Deployer

  232. Deployer

  233. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  234. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  235. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  236. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  237. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  238. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  239. module Deploye r module Action s class Processo r #

    Trunctated. def call reques t # Trunctated. text = request.tex t case text.spli t in ["help"] then hel p in "status" => status, String => name then status nam e in "version", String => name, String => version then version name, version in "deploy", String => name, String => version then deploy name, version else unknown tex t end end private # Trunctated. def help = actions.fetch(__method__).cal l def status(name) = actions.fetch(__method__).call(Success(repository[name: name]), response ) def version name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def deploy name, version actions.fetch(__method__).call Success(repository[name: name, version: version]), respons e end def unknown actio n content = %(Sorry, I don't understand: `#{action}`. Try `/deployer help` to learn more.) response.add_text(content).to_ h end end end end Deployer
  240. None
  241. Guidelines 💡

  242. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html

  243. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html • Use sorted arrays.

  244. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html • Use sorted arrays. • Use limited fi

    nds: [*, <pattern>, *].
  245. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html • Use sorted arrays. • Use limited fi

    nds: [*, <pattern>, *]. • Avoid unnecessary deconstruction.
  246. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html • Use sorted arrays. • Use limited fi

    nds: [*, <pattern>, *]. • Avoid unnecessary deconstruction. • Avoid shadow variables.
  247. Guidelines https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html • Use sorted arrays. • Use limited fi

    nds: [*, <pattern>, *]. • Avoid unnecessary deconstruction. • Avoid shadow variables. • Avoid complicated nested patterns.
  248. https://www.alchemists.io Thanks

  249. https://www.alchemists.io 🙇 Thanks