Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby,运行所有方法_Ruby_Methods_Symbols - Fatal编程技术网

Ruby,运行所有方法

Ruby,运行所有方法,ruby,methods,symbols,Ruby,Methods,Symbols,是否可以运行并输出所有方法?不确定如何通过点运算符传递符号。因此,它应该是link.node require 'mechanize' agent = Mechanize.new page = agent.get("http://stackoverflow.com/") link = page.link p meth = link.methods #=> [:node, :href, :attributes, :page, :referer, :click, :dom_id, :dom

是否可以运行并输出所有方法?不确定如何通过点运算符传递符号。因此,它应该是
link.node

require 'mechanize'

agent = Mechanize.new
page = agent.get("http://stackoverflow.com/")


link = page.link
p meth = link.methods #=> [:node, :href, :attributes, :page, :referer, :click, :dom_id, :dom_class, :pretty_print, :inspect, :rel, :rel?, :noreferrer?, :text, :to_s, :uri, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]


   #this doesn't work.
    meth.each do |x|
      puts "#{x}: #{link.x}"
    end
要求“机械化”
agent=Mechanize.new
page=agent.get(“http://stackoverflow.com/")
link=page.link
p meth=link.methods#=>[:node,:href,:attributes,:page,:referer,:click,:dom_id,:dom_class,:pretty_print,:inspect,:rel,:rel?,:noreferrer?,:text,:to_s,:uri,:pretty_print_cycle,:pretty_print_实例_变量,:pretty_print_print_inspect,:nil?,:=,:=,:=,:=,:=,:,:,:,:eql?,:散列,:,,:,,:,:class,:singleton类,:singleton类,:clone,:clone,:dup,:dup,:污染?,:未污染,:不信任,:不信任?,:信任,:冻结,:冻结?,:方法,:单例方法,:受保护的方法,:私有方法,:公共方法,:实例变量,:实例变量获取,:实例变量集,:实例变量定义?,:实例类型?,:是?,:点击,:发送,:公共发送,:响应缺少?,:extend,:display,:method,:public_method,:define_singleton_method,:object_id,:to_enum,:enum_for,:pretty_inspect,:=,:equal?,:!,:!=,:instance_eval,:instance_exec,:_send_u,:u id_u]
#这不管用。
每种药物都有| x|
放置“#{x}:#{link.x}”
终止

您可以使用
发送
,但正如评论中指出的,许多方法的算术错误:

meth.each { |x| puts "#{x}: #{link.send(x)}" }

顺便说一句:如果你想学习Ruby,我写了一个你可能感兴趣的gem:

你可以使用
send
,但是正如评论中指出的,很多方法都会有错误的算术:

meth.each { |x| puts "#{x}: #{link.send(x)}" }

顺便说一句:如果你想学习Ruby,我写了一个gem,你可能会感兴趣:

如果你想访问这个类的方法,你可以使用以下方法

调用私有方法

meth.each { |x| puts "#{x}: #{link.class.send(x)}" }
调用公共方法

meth.each { |x| puts "#{x}: #{link.send(x)}" }
使用参数或参数调用方法

meth.each { |x| puts "#{x}: #{link.class.send(x, params_or_arguments)}" }
meth.each { |x| puts "#{x}: #{link.send(x, params_or_arguments)}" }

如果要访问类的方法,可以使用以下方法

调用私有方法

meth.each { |x| puts "#{x}: #{link.class.send(x)}" }
调用公共方法

meth.each { |x| puts "#{x}: #{link.send(x)}" }
使用参数或参数调用方法

meth.each { |x| puts "#{x}: #{link.class.send(x, params_or_arguments)}" }
meth.each { |x| puts "#{x}: #{link.send(x, params_or_arguments)}" }

这些方法中有很多都需要参数,没有参数就无法调用。你想做什么?你在运行这些方法吗?另外,现在它正在输出一个字符串,其中只包含方法名,后跟不带参数传递的方法。帮助我学习。这些方法是符号,不知道如何将符号推入dot运算符…因此,不是传递
链接。:node
,而是传递
链接。node
这些方法中的许多都需要参数,没有参数就无法调用。您试图实现什么?您在运行哪些方法?另外,现在它正在输出一个字符串,其中只包含方法名,后跟传递的方法,不包含参数参数。帮助我学习。方法是符号,不知道如何将符号推入点运算符…因此,与其传递
link.:node
,不如传递
link.node
Hi Micheal.。我在这里回答了帮助(KS),不是为了名誉。我不是一个经常使用软件的人。我可以理解,这里的一切都是为了代表。希望,我没有伤害你…@Jak别担心,我不在乎,我发现这个开关有点奇怪,因为答案基本上是一样的。无论如何,我给了你另一个+1,并将删除之前的评论。希望我们能看到你在这个问题上更加积极未来:-)@Michal.你是一个大师..感谢老师的绅士们,不知道该做什么。对stack来说是个新手。Jak的答案更符合问题,但你的答案Michael对我个人来说更合适。你有什么建议?保持原样:-)如果有疑问,我同意“与问题一致”争论。嗨,迈克尔。我在这里回答了求助(KS),不是为了名誉。我不是一个经常使用软件的人。我可以理解,这里的一切都是为了代表。希望,我没有伤害你…@Jak别担心,我不在乎,我发现这个开关有点奇怪,因为答案基本上是一样的。无论如何,我给了你另一个+1,并将删除之前的评论。希望我们能看到你在这个问题上更加积极未来:-)@Michal.你是一个大师..感谢老师的绅士们,不知道该做什么。对stack来说是个新手。Jak的答案更符合问题,但你的答案迈克尔对我个人来说更合适。你有什么建议吗?保持原样:-)如果有疑问,我同意“与问题一致”的论点。