# class WIN32OLE::Method

`WIN32OLE::Method` objects represent OLE method information.

### Public Class Methods

WIN32OLE::Method.new(ole_type, method) → WIN32OLE::Method object
Source

    static VALUE
    folemethod_initialize(VALUE self, VALUE oletype, VALUE method)
    {
        VALUE obj = Qnil;
        ITypeInfo *pTypeInfo;
        if (rb_obj_is_kind_of(oletype, cWIN32OLE_TYPE)) {
            SafeStringValue(method);
            pTypeInfo = itypeinfo(oletype);
            obj = olemethod_from_typeinfo(self, pTypeInfo, method);
            if (obj == Qnil) {
                rb_raise(eWIN32OLERuntimeError, "not found %s",
                         StringValuePtr(method));
            }
        }
        else {
            rb_raise(rb_eTypeError, "1st argument should be WIN32OLE::Type object");
        }
        return obj;
    }

Returns a new `WIN32OLE::Method` object which represents the information about OLE method. The first argument ole_type specifies `WIN32OLE::Type` object. The second argument method specifies OLE method name defined OLE class which represents `WIN32OLE::Type` object.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')

### Public Instance Methods

dispid
Source

    static VALUE
    folemethod_dispid(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_dispid(pmethod->pTypeInfo, pmethod->index);
    }

Returns dispatch ID.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.dispid # => 181

event?
Source

    static VALUE
    folemethod_event(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        if (!pmethod->pOwnerTypeInfo)
            return Qfalse;
        return ole_method_event(pmethod->pOwnerTypeInfo,
                                pmethod->index,
                                rb_ivar_get(self, rb_intern("name")));
    }

Returns true if the method is event.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SheetActivate')
    puts method.event? # => true

event_interface
Source

    static VALUE
    folemethod_event_interface(VALUE self)
    {
        BSTR name;
        struct olemethoddata *pmethod;
        HRESULT hr;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        if(folemethod_event(self) == Qtrue) {
            hr = ole_docinfo_from_type(pmethod->pTypeInfo, &name, NULL, NULL, NULL);
            if(SUCCEEDED(hr))
                return WC2VSTR(name);
        }
        return Qnil;
    }

Returns event interface name if the method is event.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SheetActivate')
    puts method.event_interface # =>  WorkbookEvents

helpcontext
Source

    static VALUE
    folemethod_helpcontext(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_helpcontext(pmethod->pTypeInfo, pmethod->index);
    }

Returns help context.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.helpcontext # => 65717

helpfile
Source

    static VALUE
    folemethod_helpfile(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);

        return ole_method_helpfile(pmethod->pTypeInfo, pmethod->index);
    }

Returns help file. If help file is not found, then the method returns nil.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.helpfile # => C:\...\VBAXL9.CHM

helpstring
Source

    static VALUE
    folemethod_helpstring(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_helpstring(pmethod->pTypeInfo, pmethod->index);
    }

Returns help string of OLE method. If the help string is not found, then the method returns nil.

    tobj = WIN32OLE::Type.new('Microsoft Internet Controls', 'IWebBrowser')
    method = WIN32OLE::Method.new(tobj, 'Navigate')
    puts method.helpstring # => Navigates to a URL or file.

inspect → String
Source

    static VALUE
    folemethod_inspect(VALUE self)
    {
        return default_inspect(self, "WIN32OLE::Method");
    }

Returns the method name with class name.

invkind
Source

    static VALUE
    folemethod_invkind(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_invkind(pmethod->pTypeInfo, pmethod->index);
    }

Returns the method invoke kind.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.invkind # => 1

invoke_kind
Source

    static VALUE
    folemethod_invoke_kind(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_invoke_kind(pmethod->pTypeInfo, pmethod->index);
    }

Returns the method kind string. The string is “UNKNOWN” or “PROPERTY” or “PROPERTY” or “PROPERTYGET” or “PROPERTYPUT” or “PROPERTYPPUTREF” or “FUNC”.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.invoke_kind # => "FUNC"

name
Source

    static VALUE
    folemethod_name(VALUE self)
    {
        return rb_ivar_get(self, rb_intern("name"));
    }

Returns the name of the method.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')
    puts method.name # => SaveAs

Also aliased as: to_s
offset_vtbl
Source

    static VALUE
    folemethod_offset_vtbl(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_offset_vtbl(pmethod->pTypeInfo, pmethod->index);
    }

Returns the offset ov VTBL.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.offset_vtbl # => 40

params
Source

    static VALUE
    folemethod_params(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_params(pmethod->pTypeInfo, pmethod->index);
    }

returns array of `WIN32OLE::Param` object corresponding with method parameters.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')
    p method.params # => [Filename, FileFormat, Password, WriteResPassword,
                          ReadOnlyRecommended, CreateBackup, AccessMode,
                          ConflictResolution, AddToMru, TextCodepage,
                          TextVisualLayout]

return_type
Source

    static VALUE
    folemethod_return_type(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_return_type(pmethod->pTypeInfo, pmethod->index);
    }

Returns string of return value type of method.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.return_type # => Workbook

return_type_detail
Source

    static VALUE
    folemethod_return_type_detail(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_return_type_detail(pmethod->pTypeInfo, pmethod->index);
    }

Returns detail information of return value type of method. The information is array.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    p method.return_type_detail # => ["PTR", "USERDEFINED", "Workbook"]

return_vtype
Source

    static VALUE
    folemethod_return_vtype(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_return_vtype(pmethod->pTypeInfo, pmethod->index);
    }

Returns number of return value type of method.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.return_vtype # => 26

size_opt_params
Source

    static VALUE
    folemethod_size_opt_params(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_size_opt_params(pmethod->pTypeInfo, pmethod->index);
    }

Returns the size of optional parameters.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')
    puts method.size_opt_params # => 4

size_params
Source

    static VALUE
    folemethod_size_params(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_size_params(pmethod->pTypeInfo, pmethod->index);
    }

Returns the size of arguments of the method.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')
    puts method.size_params # => 11

name

Returns the name of the method.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
    method = WIN32OLE::Method.new(tobj, 'SaveAs')
    puts method.name # => SaveAs

Alias for: name
visible?
Source

    static VALUE
    folemethod_visible(VALUE self)
    {
        struct olemethoddata *pmethod;
        TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
        return ole_method_visible(pmethod->pTypeInfo, pmethod->index);
    }

Returns true if the method is public.

    tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbooks')
    method = WIN32OLE::Method.new(tobj, 'Add')
    puts method.visible? # => true