Ruby win32ole - how to determine the type of an OLE class, does the OLE class support a method

I am using Ruby 1.8. Using the WIN32OLE Module -

1) How to determine the class name of an instance of an OLE object? 2) How to determine if an instance of an object supports a particular method?

In an Outlook automation script, I try to delete items in the Deleted Items folder that is older than 21 days. For mail items, I want to use the ReceivedTime property, but for this I need to check if the item is really an instance of MailItem.

Secondly, the best I could come up with (very slow):

def MethodExists(obj, methodName) obj.ole_methods.each{|method| if (method.name == methodName) return true end } return false end 
+4
source share
2 answers

With particular regard to WIN32OLE objects ...

How to determine the class name of an instance of an OLE object?

 object.ole_obj_help.name 

How to determine if an instance of an object supports a particular method?

 object.ole_methods.collect!{ |x| x.to_s }.include?( 'MethodName' ) 
+7
source
  • obj.class

  •  if obj.respond_to?(methodName) #do your work end 
-3
source

All Articles