Actions
Feature #20793
closedAllow Multiple Arguments for the .is_a? Method
Feature #20793:
Allow Multiple Arguments for the .is_a? Method
Status:
Rejected
Assignee:
-
Target version:
-
Actions
Added by artemb (Artem Borodkin) over 1 year ago. Updated over 1 year ago.
Also kind_of? method?
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.
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.