# Overloading in ruby

**URL:** <https://www.ruby-forum.com/t/overloading-in-ruby/86592>\
**Category:** Ruby\
**Created:** [February 23, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/overloading-in-ruby/86592 "2007-02-23T15:13:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkejzlar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@tkejzlar](https://www.ruby-forum.com/u/tkejzlar)\
**Post date:** [February 23, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/overloading-in-ruby/86592/1 "2007-02-23T15:13:03Z")

</div>

Hi,

I’ve been doing some Ruby code interfacing with Windows COM objects and  
I’ve ran into this problem:

I have a COM object method say object.Value(name) which - when i call it  
with appropriate “name” value returns some value.

The problem is that the same is used (according to that COM lib  
documentation) for setting data to the object - i should write  
object.Value(name) = value and it should set the value.

However I have not found a way to do this in Ruby - it gives me (and I  
can fully understand why) syntax error when I try to set data to the  
object.

Does anybody know if this can be done using Ruby and possibly how?

Thanks, Tom.

---

<div class="post-metadata">

**Author:** ![tkejzlar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@tkejzlar](https://www.ruby-forum.com/u/tkejzlar)\
**Post date:** [February 23, 2007, 3:49pm UTC](https://www.ruby-forum.com/t/overloading-in-ruby/86592/2 "2007-02-23T15:49:55Z")

</div>

On 2/23/07, Tomas K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> object.Value(name) = value and it should set the value.
> 
> However I have not found a way to do this in Ruby - it gives me (and I  
> can fully understand why) syntax error when I try to set data to the  
> object.
> 
> Does anybody know if this can be done using Ruby and possibly how?
> 
> Thanks, Tom.

try:

object.Value[name] = value

or: have a look at WIN32OLE docs and see if setproperty or invoke  
could do what you want

or: post the exact code possibly with the links to the lib  
documentation.

I’m not good enough to guess a general case, but I’ve been playing  
with COM a bit so I might be able to guess the particular case.

J.

---

<div class="post-metadata">

**Author:** ![tkejzlar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@tkejzlar](https://www.ruby-forum.com/u/tkejzlar)\
**Post date:** [February 23, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/overloading-in-ruby/86592/3 "2007-02-23T16:04:10Z")

</div>

Jan,

thanks very much. Setproperty did the trick for me.

Tom.

Jan S. wrote:

> or: have a look at WIN32OLE docs and see if setproperty or invoke  
> could do what you want

---

<div class="post-metadata">

**Author:** ![tkejzlar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@tkejzlar](https://www.ruby-forum.com/u/tkejzlar)\
**Post date:** [February 23, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/overloading-in-ruby/86592/4 "2007-02-23T18:47:27Z")

</div>

When calling methods on com objects in vbscript (ugh! pain ouch ouch  
ouch!) the overlaoded methods were accessed by a \_number.

Lets say it’s the Vacuum object (the object that makes windows suck).  
In overloadable languages you can pass a Soul, an Idea, or Creativity  
into the Vacuum’s suck method. The order they are defined in is  
important because that’s the order (as far as I was able to figure  
out) that they are indexed in.  
To use Vacuum to suck a soul it would be  
myVaccum.suck\_1(someonesSoul)  
an idea would be  
myVaccum.suck\_2(goodIdeasAboutGuis)

But that was just in vbscript.

–Kyle
