Hacker News new | ask | show | jobs
by ezekg 1272 days 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).

[0]: https://github.com/rails/rails/pull/45553

2 comments

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).

I don’t understand the issue - why was it reverted? Are there multiple ways to do pattern matching? Why?
I read that comment, but unless you know Ruby most of the specifics are meaningless
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.

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.