Domanda

I am consuming a web service using ruby (1.8.7) and soap4r (1.5.8). The web service has a method named "type" and I am not able to get the value.

@driver=SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
result = @driver.GetJob(:jobid => "123")
puts "jobname is #{result.name}"
puts "jobtype is #{result.type}"

The fourth line gives me "warning: Object#type is deprecated; use Object#class". I know that Object.type is deprecated. I want to call the "type" method of the result obtained from the web service. I don't own the web service so I can't change it.

Any help appreciated. Thanks in advance.

È stato utile?

Soluzione

The type method is probably invoked using method_missing and when the method exists on Object this mechanism doesn't work. If so this little piece of monkey patching gets rid of Object.type:

class Object
  undef_method :type
end

Put this code somewhere before the call to the web service and it should work.

Another way to solve it is upgrading to ruby 1.9. The type method is gone!

Altri suggerimenti

I would look for a method that allows you to pass in a symbol representing the attribute you want. It'd be something like

puts "jobtype is #{result.some_method(:type)}"

or (less likely)

puts "jobtype is #{result.some_method("type")}"

@froderik's answer may help you for one particular scenario, but what if the attribute you wanted was called "class", or "send", or "initialize"? The soap library would have to handle such scenarios somehow, unless it was badly designed.

Just guessing, but how about result['type']? Or result[:type] ?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top