简体   繁体   English

Ruby - 打印每个循环中的所有方法

[英]Ruby - Print all methods in each loop

How can I print all methods for network_sg in the following code?如何在以下代码中打印network_sg的所有方法? I'm not sure what methods are available.我不确定有哪些方法可用。

Is it possible to print all methods?是否可以打印所有方法? It has Name but not sure what other methods are available.它有Name ,但不确定还有哪些其他方法可用。

network_sg = Azure::Armrest::Network::NetworkSecurityGroupService.new(conf)

network_sg.list(rg).each do |network_sg|
    $evm.log('info', "azure network_sg test is: #{network_sg.name} ")
end

You can see what methods are available by using the .methods method.您可以使用.methods方法查看可用的方法。 This will return an array of all the methods accessible to use (note that it won't show any private methods).这将返回一个包含所有可以使用的方法的数组(请注意,它不会显示任何私有方法)。 I like to use it like puts(network_sg.methods - Object.new.methods).inspect to filter out all of the top level object methods and print out all of the non top level methods that are available.我喜欢像puts(network_sg.methods - Object.new.methods).inspect一样使用它来过滤掉所有顶级 object 方法并打印出所有可用的非顶级方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM