Today I learn that it is possible to call Ruby's lambdas using the triple equal operator.

I use this capacity to create nice one liners without redundant `.call`

#Ruby #til #DevTips

@notgrm I would not recommend doing this. It might work, but it's very confusing.

I generally think you shouldn't use === directly, only as part of a case expression (where this behaviour makes more sense).

Another option is also to use [], like missing_or_wildcard[filters[:country]].

Although in this case I'd usually just break out missing_or_wildcard into a method, so you can write the most obvious code.

As a more crazy option, you can do something like this to avoid needing the helper at all, by factoring out the whole loop:

base_scope.where([:country, :recipient, :sender].index_with { filters[it] unless filters[it].in?(['*', nil]) }.compact)

I've left it in one line for ease of tooting, but obviously you could break it out more.

@notgrm Filter parameters tend to bring a lot of boilerplate. It’s why I created Filterameter.

https://rockridgesolutions.com/posts/filterameter

Filterameter: Simplify and Speed Up Development of Rails Controllers

Handling filter parameters for index endpoints in Rails controllers can often be a repetitive and error-prone task. The Filterameter gem aims to simplify this process by providing a declarative way to define search filters. In this post, we’ll explore how Filterameter can help you write cleaner and more maintainable code.

Rockridge Solutions

@notgrm

That feature is useful because #=== allows lambdas to be used as conditions in case statements.

But worth noting that the #[] is probably better as a generic call shorthand.

Example:

```
is_even = ->(x) { x.even? }
is_even[2] #=> true
```

Good info, I'm going to try it to see how it works.