Re:"Useless Ruby sugar": Pattern matching (Pt. 2)
by ezekg on Friday October 27, 2023 @12:21PM
(#38040527)
> The closest you can go is this, but having an explicit rightward assignment:
>
> events.select { _1 => type:, role:; type == 'create' || role == 'admin' }
I'd actually recommend using in instead:
events.select { _1 in {type: 'create'} | {role: 'admin'} }
I really enjoy using in for filtering. But I get the OP's point.
Pattern matching does need QOL improvements to really feel like it's a first-class citizen of the language ... like patterning matching for method and block arguments. :)
>
> events.select { _1 => type:, role:; type == 'create' || role == 'admin' }
I'd actually recommend using in instead:
I really enjoy using in for filtering. But I get the OP's point.Pattern matching does need QOL improvements to really feel like it's a first-class citizen of the language ... like patterning matching for method and block arguments. :)