gpt4 book ai didi

ruby - 为什么 Ruby 没有 is_an?方法?

转载 作者:数据小太阳 更新时间:2023-10-29 08:14:58 26 4
gpt4 key购买 nike

为什么 Ruby 没有 is_an? 方法?例如:

[].is_an? Array?

最佳答案

您可以考虑使用 is_a?相反,例如:

if [].is_a? Array
puts "Array"
end

如果你真的需要 is_an? 你也可以用别名来实现它:

class Object
alias :is_an? :is_a?
end

if [].is_an? Array
puts "Array"
end

关于ruby - 为什么 Ruby 没有 is_an?方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9374260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com