# How can you return the Rubified version of a CLR object back to the CLR?

**URL:** <https://www.ruby-forum.com/t/how-can-you-return-the-rubified-version-of-a-clr-object-back-to-the-clr/202748>\
**Category:** IronRuby\
**Created:** [February 4, 2011, 10:45pm UTC](https://www.ruby-forum.com/t/how-can-you-return-the-rubified-version-of-a-clr-object-back-to-the-clr/202748 "2011-02-04T22:45:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 4, 2011, 10:45pm UTC](https://www.ruby-forum.com/t/how-can-you-return-the-rubified-version-of-a-clr-object-back-to-the-clr/202748/1 "2011-02-04T22:45:24Z")

</div>

Using IronRuby from C# is like a one-way street. I can take a C#  
object, and use it from the DLR. But I can’t enhance that object and  
return it back to C#. When I return it back, it looses all the Ruby  
joy!

I’ve got an example of what I mean at [http://pastie.org/1529598](http://pastie.org/1529598)

How can I get a CLR object back from IronRuby that keeps all the  
goodness that Ruby gave it?

= Greg

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 5, 2011, 12:31am UTC](https://www.ruby-forum.com/t/how-can-you-return-the-rubified-version-of-a-clr-object-back-to-the-clr/202748/2 "2011-02-05T00:31:06Z")

</div>

This is by design. System.String doesn’t really have “reverse” method.  
IronRuby just pretends it’s there to make work more like Ruby string. So  
while you’re writing Ruby code you use these convenience methods, but  
once you’re in another context (another language, be it C#, or Python)  
you won’t see them.

Tomas

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 7, 2011, 4:29pm UTC](https://www.ruby-forum.com/t/how-can-you-return-the-rubified-version-of-a-clr-object-back-to-the-clr/202748/3 "2011-02-07T16:29:32Z")

</div>

But there is an Object that is a Ruby string which does understand  
#reverse. Is there a way to get that object from Ruby back to the DLR?

Take a look at: [http://pastie.org/1537151](http://pastie.org/1537151)

Using SimpleDelegator I can send back a delegate to Ruby’s string and  
access the reverse method.

Unfortunately, since the reversed string is sent back to the CLR, its a  
System::String. So I couldn’t call str.reverse().reverse().

It should be possible to get back a Ruby String (or any other Ruby  
object) and use it from C#. Without this, you can not effectively use  
IronRuby to enhance a legacy C# project. It is like having a Berlin  
Wall between the CLR and DLR. As a visitor you can get into the DLR.  
But as a citizen you cant get out of the DLR!
