모든 메소드를 실행하고 출력 할 수 있습니까? 점 연산자를 통해 기호를 전달하는 방법을 모릅니다. BTWRuby, 모든 메소드 실행
meth.each { |x| puts "#{x}: #{link.send(x)}" }
: 당신이 경우에 따라서 대신 link.:node
의 그것은 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
이러한 방법 중 많은 인수가 필요하고 호출 할 수 없습니다와 메소드를 호출하기 위해 공공 방법
를 호출하려면 개인 방법
를 호출하려면 그들없이. 무엇을 성취하려고합니까? – PinnyM
당신은 어떻게 그 방법을 실행하고 있습니까? 또한 메서드 이름 뒤에 인자가없는 메서드가 전달 된 문자열을 출력하고 있습니다. – sunnyrjuneja
나를 도와줍니다. 메소드는 심볼이며 도트 연산자에 심볼을 푸는 방법을 모른다. 그래서'link. : node'를 전달하는 대신에'link.node'가되어야한다. –