Expect looks like except

Rails 8 introduced params.expect for ActionController::Parameters . This is really nice piece of functionality. We can now express tight strong params requirements more easily.

One thing bugs me though: expect looks like except. When I read something like

params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
params.expect(:a, :b)

then at a first glance I think that only :c will end up being returned. Which is very much the opposite of the intention and would look like this:

params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
params.except(:a, :b)

I thought I would get used to it, but I didn’t. Would there be a proper alias we could propose? Something like anticipate or promise?

Update: I even had to fix the example above because I swapped the verbs :man_facepalming: .

5 Likes

This was discussed during the initial development. I’m copying dhh’s response here for context:

Appreciate the feedback here, but this bikesheed has already been painted, @p8. We’re moving on to other bikesheeds now