Ruby win32ole - 如何确定OLE类类型,OLE类是否支持方法

bva*_*erw 4 ruby outlook win32ole

我使用的是Ruby 1.8.使用WIN32OLE模块 -

1)如何确定OLE对象实例的类名?2)如何判断对象实例是否支持特定方法?

在Outlook自动化脚本中,我尝试删除"已删除邮件"文件夹中超过21天的项目.对于邮件项目,我想使用ReceivedTime属性,但为了做到这一点,我需要检查该项目是否实际上是一个MailItem实例.

第二,我能想到的最好的是(真的很慢):

def MethodExists(obj, methodName)
  obj.ole_methods.each{|method|
    if (method.name == methodName)
      return true
    end
  }
  return false
end
Run Code Online (Sandbox Code Playgroud)

小智 7

具体考虑WIN32OLE对象......

如何确定OLE对象实例的类名?

object.ole_obj_help.name
Run Code Online (Sandbox Code Playgroud)

如何判断对象实例是否支持特定方法?

object.ole_methods.collect!{ |x| x.to_s }.include?( 'MethodName' )
Run Code Online (Sandbox Code Playgroud)