# C# method returns string to IronRuby - how it automatically be a IronRuby string?

**URL:** <https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716>\
**Category:** IronRuby\
**Created:** [April 16, 2009, 6:16pm UTC](https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716 "2009-04-16T18:16:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [April 16, 2009, 6:16pm UTC](https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716/1 "2009-04-16T18:16:49Z")

</div>

Hello,

Just hosted the DLR within an application to allow users some  
scripting functionality. Part of the functionality is that you can  
call a C# method and have a string returned. However, the string is  
always being returned as a ClrString which means methods like \<\< don’t  
work which is annoying. Having to write to\_s after every call isn’t  
great for my nice clean DSL 🙂

How can I get around this? I want my C# method to return Ruby string.

Thanks

Ben

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [April 16, 2009, 7:02pm UTC](https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716/2 "2009-04-16T19:02:38Z")

</div>

## Monkey patch ClrString with the methods you need? Or make your C# method return MutableString if you are able to

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
GSM: +32.486.787.582  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [April 16, 2009, 7:34pm UTC](https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716/3 "2009-04-16T19:34:22Z")

</div>

Do you have the latest build of IronRuby?  
Non-mutable Ruby methods are implemented there on CLR strings.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Thursday, April 16, 2009 9:12 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] C# method returns string to IronRuby - how  
it automatically be a IronRuby string?

## Monkey patch ClrString with the methods you need? Or make your C# method return MutableString if you are able to

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
GSM: +32.486.787.582  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

On Thu, Apr 16, 2009 at 5:59 PM, Ben H.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
Hello,

Just hosted the DLR within an application to allow users some  
scripting functionality. Part of the functionality is that you can  
call a C# method and have a string returned. However, the string is  
always being returned as a ClrString which means methods like \<\< don’t  
work which is annoying. Having to write to\_s after every call isn’t  
great for my nice clean DSL 🙂

How can I get around this? I want my C# method to return Ruby string.

Thanks

Ben

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [April 16, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/c-method-returns-string-to-ironruby-how-it-automatically-be-a-ironruby-string/165716/4 "2009-04-16T22:55:19Z")

</div>

I am using 0.3 build but I can grab the latest tomorrow. If that fails  
I will give MutableString strings a try - thanks for the responses 🙂

On Thu, Apr 16, 2009 at 6:27 PM, Tomas M.
