DEV Community

Discussion on: Find your way in Ruby Pattern matching

Collapse
 
rhymes profile image
rhymes

Declarative programming for the win!

It seem powerful, thanks for writing about it.

It reminds me of pattern matching in Erlang and the sort of declarative matching Go does with JSON.

I wonder how faster/slower it'd be than checking stuff manually, this slide clearly shows how more direct the code looks - even though it might be slightly less readable as probably Rubysts are more accustomed to following conditional logic than these declarations. Especially "variable binding" and the "pin operator" :D

They also added "if/unless preconditions" which once again remind me of Erlang and its "guards".

I'm really, really excited about this! Hopefully it'll be stable for the next major release of Ruby and we can start using it :D

A tip: you can add syntax highlighting to your example by adding the language name after the triple backticks:

case 67
  in 0..100

was written as:

Collapse
 
uryelah profile image
uryelah

Thank you I didn't know that!
Yeah, I heard it's not that performative right now but hopefully it will be faster in the future versions.