* [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method
@ 2024-10-10 8:50 artemb (Artem Borodkin) via ruby-core
2024-10-10 9:55 ` [ruby-core:119503] " nobu (Nobuyoshi Nakada) via ruby-core
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: artemb (Artem Borodkin) via ruby-core @ 2024-10-10 8:50 UTC (permalink / raw)
To: ruby-core; +Cc: artemb (Artem Borodkin)
Issue #20793 has been reported by artemb (Artem Borodkin).
----------------------------------------
Feature #20793: Allow Multiple Arguments for the .is_a? Method
https://bugs.ruby-lang.org/issues/20793
* Author: artemb (Artem Borodkin)
* Status: Open
----------------------------------------
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
``` ruby
name.is_a? String, Symbol
```
Currently, we need to write the following to achieve the same functionality:
``` ruby
[String, Symbol].include?(name.class)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119503] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method
2024-10-10 8:50 [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method artemb (Artem Borodkin) via ruby-core
@ 2024-10-10 9:55 ` nobu (Nobuyoshi Nakada) via ruby-core
2024-10-10 10:48 ` [ruby-core:119504] " Eregon (Benoit Daloze) via ruby-core
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-10-10 9:55 UTC (permalink / raw)
To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)
Issue #20793 has been updated by nobu (Nobuyoshi Nakada).
Also `kind_of?` method?
----------------------------------------
Feature #20793: Allow Multiple Arguments for the .is_a? Method
https://bugs.ruby-lang.org/issues/20793#change-110118
* Author: artemb (Artem Borodkin)
* Status: Open
----------------------------------------
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
``` ruby
name.is_a? String, Symbol
```
Currently, we need to write the following to achieve the same functionality:
``` ruby
[String, Symbol].include?(name.class)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119504] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method
2024-10-10 8:50 [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method artemb (Artem Borodkin) via ruby-core
2024-10-10 9:55 ` [ruby-core:119503] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-10-10 10:48 ` Eregon (Benoit Daloze) via ruby-core
2024-10-10 11:21 ` [ruby-core:119505] " artemb (Artem Borodkin) via ruby-core
2024-11-07 8:58 ` [ruby-core:119794] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-10-10 10:48 UTC (permalink / raw)
To: ruby-core; +Cc: Eregon (Benoit Daloze)
Issue #20793 has been updated by Eregon (Benoit Daloze).
I think pattern matching can/should be used here instead of making `is_a?` more complicated:
```
irb(main):001:0> name = :abc
=> :abc
irb(main):002:0> name in String | Symbol
=> true
irb(main):003:0> name = 42
=> 42
irb(main):004:0> name in String | Symbol
=> false
```
`is_a?` is deeply optimized so accepting multiple arguments would likely make it slower or complicate things significantly.
----------------------------------------
Feature #20793: Allow Multiple Arguments for the .is_a? Method
https://bugs.ruby-lang.org/issues/20793#change-110119
* Author: artemb (Artem Borodkin)
* Status: Open
----------------------------------------
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
``` ruby
name.is_a? String, Symbol
```
Currently, we need to write the following to achieve the same functionality:
``` ruby
[String, Symbol].include?(name.class)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119505] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method
2024-10-10 8:50 [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method artemb (Artem Borodkin) via ruby-core
2024-10-10 9:55 ` [ruby-core:119503] " nobu (Nobuyoshi Nakada) via ruby-core
2024-10-10 10:48 ` [ruby-core:119504] " Eregon (Benoit Daloze) via ruby-core
@ 2024-10-10 11:21 ` artemb (Artem Borodkin) via ruby-core
2024-11-07 8:58 ` [ruby-core:119794] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: artemb (Artem Borodkin) via ruby-core @ 2024-10-10 11:21 UTC (permalink / raw)
To: ruby-core; +Cc: artemb (Artem Borodkin)
Issue #20793 has been updated by artemb (Artem Borodkin).
Eregon (Benoit Daloze) wrote in #note-2:
> I think pattern matching should be used here instead
Very nice, thank you!
If kind_of? (and alias is_a?) has a strong implementation optimization, I agree that this is not so important enhancement.
----------------------------------------
Feature #20793: Allow Multiple Arguments for the .is_a? Method
https://bugs.ruby-lang.org/issues/20793#change-110120
* Author: artemb (Artem Borodkin)
* Status: Open
----------------------------------------
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
``` ruby
name.is_a? String, Symbol
```
Currently, we need to write the following to achieve the same functionality:
``` ruby
[String, Symbol].include?(name.class)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:119794] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method
2024-10-10 8:50 [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method artemb (Artem Borodkin) via ruby-core
` (2 preceding siblings ...)
2024-10-10 11:21 ` [ruby-core:119505] " artemb (Artem Borodkin) via ruby-core
@ 2024-11-07 8:58 ` matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-11-07 8:58 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #20793 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
`is_a?(A, B)` can be read as `is_a?(A) || is_a?(B)` or `is_a?(A) && is_a?(B)`. This ambiguity might lead to less readability.
Matz.
----------------------------------------
Feature #20793: Allow Multiple Arguments for the .is_a? Method
https://bugs.ruby-lang.org/issues/20793#change-110479
* Author: artemb (Artem Borodkin)
* Status: Rejected
----------------------------------------
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
``` ruby
name.is_a? String, Symbol
```
Currently, we need to write the following to achieve the same functionality:
``` ruby
[String, Symbol].include?(name.class)
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-07 8:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-10 8:50 [ruby-core:119502] [Ruby master Feature#20793] Allow Multiple Arguments for the .is_a? Method artemb (Artem Borodkin) via ruby-core
2024-10-10 9:55 ` [ruby-core:119503] " nobu (Nobuyoshi Nakada) via ruby-core
2024-10-10 10:48 ` [ruby-core:119504] " Eregon (Benoit Daloze) via ruby-core
2024-10-10 11:21 ` [ruby-core:119505] " artemb (Artem Borodkin) via ruby-core
2024-11-07 8:58 ` [ruby-core:119794] " matz (Yukihiro Matsumoto) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).