An 'in' operator for Ruby?

An 'in' operator for Ruby?

I have had two fairly small changes I wanted to make in Ruby. The first was realized years ago -- hashes now preserve insertion order and iterate in a predictable way. That's fairly minor, but it did/does have some use cases, and it had no impact on performance. Here's another one. Personally, this is a bigger thing to me.

I've always believed personally that Ruby should have an `in` operator.

I've mentioned this in speaking (including lightning talks) and in writing. It's not a giant big deal for me, but it is one of my personal favorite ideas. Here are some details.

My proposal

I propose to let x in y be syntax sugar for y.include? x

You may ask: Why?

Frequently Whined Whines


People have ignored me on this for at least ten years. They probably still will. That, as they say, is life.

Back Home