# VB.Net - Ruby interop

**URL:** <https://www.ruby-forum.com/t/vb-net-ruby-interop/189755>\
**Category:** IronRuby\
**Created:** [June 7, 2010, 7:54am UTC](https://www.ruby-forum.com/t/vb-net-ruby-interop/189755 "2010-06-07T07:54:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian\_Bishop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@Julian\_Bishop](https://www.ruby-forum.com/u/Julian_Bishop)\
**Post date:** [June 7, 2010, 7:54am UTC](https://www.ruby-forum.com/t/vb-net-ruby-interop/189755/1 "2010-06-07T07:54:05Z")

</div>

Hi,

A couple of technical questions regarding how to leverage Ruby from  
[VB.Net](http://VB.Net)  
and vice versa:

1. Is the ScriptScope the only option for passing object refs into Ruby?  
I  
mean can they also be passed as parameters to the Ruby methods called by  
InvokeMember?

2. Ruby has no need for passing parameters “ByRef” like you can in VB  
because Ruby’s return statement so naturally returns an arbitrary list  
of  
objects as an array, and Ruby supports multiple assignment on a single  
line.  
But I have legacy VB methods with ByRef parameters that really do change  
which objects the parameters reference in the caller. I would like to be  
able to call these VB methods from Ruby code, but since Ruby has no such  
thing as ByRef, I don’t know what kind of behavior I should expect. Can  
the  
Ruby variables passed as parameters get reassigned by VB code to point  
to VB  
objects without any additional shenanigans? If not, then is there an  
established workaround for ByRef parameters? Has this odd situation been  
addressed yet? (I don’t want to rewrite/retest legacy code that already  
works just fine).

Thanks,

Julian.

---

<div class="post-metadata">

**Author:** ![Julian\_Bishop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@Julian\_Bishop](https://www.ruby-forum.com/u/Julian_Bishop)\
**Post date:** [June 7, 2010, 10:46pm UTC](https://www.ruby-forum.com/t/vb-net-ruby-interop/189755/2 "2010-06-07T22:46:57Z")

</div>

1. 

```
 Yes, you can pass parameters via InvokeMember.

```

2. 

```
 You can call methods with ByRefs from Ruby. An example could be 

```

Dictionary\<int, int\>.TryGetValue:

> > > dict = System::Collections::Generic::Dictionary[Fixnum, Fixnum].new  
> > > =\> System.Collections.Generic.Dictionary`2[System.Int32,System.Int32]  
> > > dict.add 1,2  
> > > =\> nil  
> > > dict.try\_get\_value 1  
> > > =\> [true, 2]

The second parameter to TryGetvalue is an ByRef. You can either  
omit an argument for such parameter or pass an instance of  
System.Runtime.CompilerServices.StrongBox. If you omit the argument  
the result is returned in the return value (as shown above). If you pass  
an instance of StrongBox the value is updated in situ.

Similarly for in-out ByRef parameters. You pass in the input value and  
either get the output value in the resulting array or the StrongBox  
value if you use a StrongBox instance.

Tomas

From: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Julian Bishop  
Sent: Sunday, June 06, 2010 10:33 PM  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] [VB.Net](http://VB.Net) - Ruby interop

Hi,

A couple of technical questions regarding how to leverage Ruby from  
[VB.Net](http://VB.Net) and vice versa:

1. Is the ScriptScope the only option for passing object refs into Ruby?  
I mean can they also be passed as parameters to the Ruby methods called  
by InvokeMember?

2. Ruby has no need for passing parameters “ByRef” like you can in VB  
because Ruby’s return statement so naturally returns an arbitrary list  
of objects as an array, and Ruby supports multiple assignment on a  
single line. But I have legacy VB methods with ByRef parameters that  
really do change which objects the parameters reference in the caller. I  
would like to be able to call these VB methods from Ruby code, but since  
Ruby has no such thing as ByRef, I don’t know what kind of behavior I  
should expect. Can the Ruby variables passed as parameters get  
reassigned by VB code to point to VB objects without any additional  
shenanigans? If not, then is there an established workaround for ByRef  
parameters? Has this odd situation been addressed yet? (I don’t want to  
rewrite/retest legacy code that already works just fine).

Thanks,

Julian.
