4

我正在使用 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
4

2 回答 2

7

具体到 WIN32OLE 对象...

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

object.ole_obj_help.name

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

object.ole_methods.collect!{ |x| x.to_s }.include?( 'MethodName' )
于 2009-02-27T18:49:17.367 回答
-3
  1. obj.class

  2. if obj.respond_to?(methodName)
        #do your work
    end
    
于 2009-02-27T15:59:28.757 回答