-
Notifications
You must be signed in to change notification settings - Fork 227
core: Array#include? and Enumerable#include? should take non-Elem types #2273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
For example, `Array[Integer]` can take other number types validly: ``` > [1, 2, 3].include? 2.0 => true > [1, 2, 3].include? Complex(2) => true > [1, 2, 3].include? Rational(2) => true ``` refs: soutaro/steep#1482
|
In reality, it seems that the irb(main):005> TracePoint.new(:a_call) { |tp| p tp }.enable { [1, 2, 3].include? 2.0 }
#<TracePoint:b_call (irb):5>
#<TracePoint:c_call 'include?' (irb):5>
#<TracePoint:c_call '==' (irb):5>
#<TracePoint:c_call '==' (irb):5>
=> trueHowever, since |
| # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying). | ||
| # | ||
| def include?: (Elem object) -> bool | ||
| def include?: (untyped object) -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I thought to allow taking nil value. Therefore I changed this type as follows once:
| def include?: (untyped object) -> bool | |
| def include?: (Elem? object) -> bool | |
| | (untyped object) -> false |
But I noticed it does not help the numbers' case. Therefore, I used untyped here finally.
|
I prefer keeping the strict method type, because finding a code passing an unexpected object to Can you share the code where you want this? @tk0miya |
|
Ah, soutaro/steep#1482... %w,true,.include?(ENV['foo'])Hmm... |
|
No conclusion yet, though I'm not very positive about this change. |
For example,
Array[Integer]can take other number types validly:refs: soutaro/steep#1482