5 ms·
I was pretty sad to see the pattern matching PR reverted for 7.1 [0], but I guess the Rails team wants to make sure they nail the execution (?) even if that mea
by ezekg 4y ago
I was pretty sad to see the pattern matching PR reverted for 7.1 [0], but I guess the Rails team wants to make sure they nail the execution (?) even if that means being late to the pattern matching party, which is arguably one of the best additions to Ruby since the 1.9.3 hash syntax.
For now, I'm good with the little gem that kddnewton put together (https://github.com/kddnewton/rails-pattern_matching https://github.com/kddnewton/rails-pattern_matching).
[0]: https://github.com/rails/rails/pull/45553 https://github.com/rails/rails/pull/45553
- orf 4y agoI don’t understand the issue - why was it reverted? Are there multiple ways to do pattern matching? Why?
- ezekg 4y agoI 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.
- ohbarye 4y agoThis comment describes well. https://github.com/rails/rails/pull/45553#issuecomment-1179568855 https://github.com/rails/rails/pull/45553#issuecomment-11795...
- orf 4y agoI read that comment, but unless you know Ruby most of the specifics are meaningless
- riffraff 4y agothink 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.
- canadianfella 4y ago
- drchiu 4y agoYup, 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).