Skip to content

Enumerable#include? should receive any object#2849

Open
HoneyryderChuck wants to merge 1 commit intoruby:masterfrom
HoneyryderChuck:patch-2
Open

Enumerable#include? should receive any object#2849
HoneyryderChuck wants to merge 1 commit intoruby:masterfrom
HoneyryderChuck:patch-2

Conversation

@HoneyryderChuck
Copy link
Contributor

this checks only if an object exists in the collection, regardless of type. ruby does not raise an exception if the types don't match.

this checks only if an object exists in the collection, regardless of type. ruby does not raise an exception if the types don't match.
@soutaro
Copy link
Member

soutaro commented Feb 16, 2026

This behavior is intentional. The goal is to detect more type errors arising from a commonly seen pattern like this:

hash = { foo: :bar } #: Hash[Symbol, Symbol]
hash["foo"]          # This is usually a mistake.

I'm open to discuss this issue here to have some conclusion. Do you have any practical examples or real-world scenarios where the proposed one worked better?

(From a type-theoretic perspective, the current implementation (using T) is inconsistent. Having top/untyped is better -- consistent and sound.)

@soutaro soutaro added this to the RBS 4.0 milestone Feb 16, 2026
@sampersand
Copy link
Contributor

It'd be nice if we could have a signature like:

def []: (K) ->V?
      | (untyped) -> nil

And then that way whenever you use x = hash["foo"] or fail; x + 1 you might get an error because x would be bot

@ParadoxV5
Copy link
Contributor

Oh, we do. I opened #1875 a year and a half ago, and that was suggested even before that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants