Re:Overview Of Upcoming Rails 7.1 Features Part 1
by orf on Tuesday December 20, 2022 @10:55AM
(#34067635)
I don’t understand the issue - why was it reverted? Are there multiple ways to do pattern matching? Why?
Re:Overview Of Upcoming Rails 7.1 Features Part 1
by ohbarye on Tuesday December 20, 2022 @11:14AM
(#34067944)
This comment describes well.
https://github.com/rails/rails/pull/45553#issuecomment-11795...
Re:Overview Of Upcoming Rails 7.1 Features Part 1
by orf on Tuesday December 20, 2022 @11:22AM
(#34068055)
I read that comment, but unless you know Ruby most of the specifics are meaningless
Re:Overview Of Upcoming Rails 7.1 Features Part 1
by riffraff on Tuesday December 20, 2022 @01:48PM
(#34070390)
think of pattern matching being implemented via methods on an object which return a hash/array (deconstruct and deconstruct_keys).
ActiveRecord objects wrap an hash of attributes, but are also normal objects which have instance variables and methods plus some hooks and specific API that can be expected to be overriden.
So it's unclear how the method should behave: just read from the hash? Invoke some specific method? Invoke any method?
The answer may be non obvious.
Re:Overview Of Upcoming Rails 7.1 Features Part 1
by ezekg on Tuesday December 20, 2022 @11:10AM
(#34067888)
I think it was reverted because the Rails team isn't sure what values of a model should be available to pattern match, and how each attribute or association should be pattern matched.
Re:Overview Of Upcoming Rails 7.1 Features Part 1
by drchiu on Tuesday December 20, 2022 @12:01PM
(#34068686)
Yup, I was hoping this would make it to 7-1 but I suppose there were too many cases to consider.
I wonder if certain features could be marked as "experimental" by Rails core like they do in Ruby, and include them without the promise that the API would be stable (or even be present at all in the future).
For now, I'm good with the little gem that kddnewton put together (https://github.com/kddnewton/rails-pattern_matching).
[0]: https://github.com/rails/rails/pull/45553