Using win32ole "connect" method on Ironruby

When trying to use the connect method inside the win32ole module.
Ironruby pops up:

“undefined method ‘connect’ for WIN32OLE:Class”

I see that has been logged as an official issue at:

http://ironruby.codeplex.com/workitem/4612

However, it has not been assigned to anyone to fix and previous
questions on it went unanswered. I personally have many programs using
this method that I would like to use through Ironruby without rewriting
using .net methods.

Just testing to see if this issue is on anybody’s radar. Is it simple or
complex to solve? I understand there are probably many issues more
important than this but I am just wanting to know if I need to start
rewriting my programs or will this issue be resolved in the near future.

Timothy

On Tue, Nov 9, 2010 at 5:06 PM, Timothy B. [email protected]
wrote:

questions on it went unanswered. I personally have many programs using
this method that I would like to use through Ironruby without rewriting
using .net methods.

Just testing to see if this issue is on anybody’s radar. Is it simple or
complex to solve? I understand there are probably many issues more
important than this but I am just wanting to know if I need to start
rewriting my programs or will this issue be resolved in the near future.

Why rewriting your programs if you can just add a patch to ironruby?

I would love to write a patch to ironRuby. However, I am not sure about
how to do that. I am not even really sure where to look for the issue in
the ironruby library, nor I do I really have git fully figured out to
submit my patch back to ironruby.

I am still trying to get up to speed on how all this works
(contributing). I will be glad to try. Any direction towards where to
find and solve this issue would help!

Checkout(by that I mean get a copy) the code from github.

The IronRuby implementation of win32ole is in
Languages/Ruby/Libs/win32ole.rb, it uses System.__ComObject from the
.NET
world to implement the interface (as the header comment tells one).

If you are familiar with COM Objects (I am not) and you know how to
achieve
the functionality of WIN32OLE.connect with System.__ComObject C# then it
should be straight obvious what you need to do. Just use some interop
magic
in win32ole.rb to utilize the .NET world.

Your implementation should comply with the standard WIN32OLE
implementation
in ruby, you can easily look it up in
http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/classes/WIN32OLE.html#M001628,
just
click [Source].

If you are not familiar with COM in C#, well, there are plenty of
tutorials
on the net.

Just implement the function as clean as possible, commit, add a testcase
to
Languages/Ruby/Tests/Interop/com/win32ole_spec.rb, commit, verify if it
works with your code and the testcase, make a pull request on github.

Contributing is easy: fork the repo, make the changes, add tests
covering the new functionality (ideally as specs to
Languages/Ruby/Tests/mspec/rubyspec), run all the tests (irtests command
in Languages\Ruby\Scripts), and if everything passes push your changes
to your fork and send a pull request to the mailing list.

See https://github.com/ironruby/ironruby/wiki/Getting-the-sources

Tomas

It appears to be that the WIN32OLE.connect method cannot be fixed as
long as the WIN32OLE is class in IronRuby. This is b/c the connect
method substitutes for the new(initialize) method when called. I don’t
believe ruby allows you to create a class instance with out calling the
new method. Therefore, I see (2) possible solutions:

  1. Change WIN32OLE to a module not a class and have the ability to call
    connect or new.

  2. Add a connect method to WIN32OLE class and change the way connect has
    to be coded to connect to a running instance of an application.

I have attached a file showing a possible way to accomplish solution #1.

My questions are:
Which way should it go?
And are there issues that would come up if WIN32OLE were a module and
not a class?

Thanks for any help on this.

Timothy

Thanks for the help. I will see what I can do.

Timothy

I don’t believe ruby allows you to create a class instance with out calling the
new method.

maybe #allocate?