我正在调试一个应用程序,我需要检查DNS查询的资源类是否为IN类型。这是我发现的:
[6] pry(#<DNS::Server>)> resource_class
=> Resolv::DNS::Resource::IN::A
[7] pry(#<DNS::Server>)> resource_class.inspect
=> "Resolv::DNS::Resource::IN::A"
[8] pry(#<DNS::Server>)> resource_class.class.name
=> "Class"
[9] pry(#<DNS::Server>)> resource_class.kind_of? Class
=> true
[10] pry(#<DNS::Server>)> resource_class.kind_of? Resolv::DNS::Resource::IN::A
=> false
[11] pry(#<DNS::Server>)> resource_class.instance_of? Class
=> true
[12] pry(#<DNS::Server>)> resource_class.instance_of? Resolv::DNS::Resource::IN::A
=> false
[13] pry(#<DNS::Server>)> resource_class.is_a? Class
=> true
[14] pry(#<DNS::Server>)> resource_class.is_a? Resolv::DNS::Resource::IN::A
=> false
我试图使用无效的resource_class.instance_of? Resolv::DNS::Resource::IN::A
进行检查。我该如何检查?
答案 0 :(得分:3)
您的resource_class
是一个班级。它不是Resolv::DNS::Resource::IN::A
的实例;它是 Resolv::DNS::Resource::IN::A
。因此,简单的比较就足够了:
resource_class == Resolv::DNS::Resource::IN::A