Feature #20793
open
Allow Multiple Arguments for the .is_a? Method
Added by artemb (Artem Borodkin) 26 days ago.
Updated 26 days ago.
Description
I propose allowing multiple arguments to be passed to the .is_a? Method imply "OR" semantics:
name.is_a? String, Symbol
Currently, we need to write the following to achieve the same functionality:
[String, Symbol].include?(name.class)
I think pattern matching 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.
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.
Also available in: Atom
PDF
Like0
Like0Like4Like0