tags:

views:

236

answers:

1

Hi and good evening, hope someone can help.

I am trying to get some sort of scripting support going. I have the following code, which executes a ruby method and returns the result. However, it is returning a "method not found error" from IronRuby itself.

var engine = IronRuby.Ruby.CreateEngine();
returnvalue = engine.Operations.InvokeMember(instance, method, arg).ToString();

I am running the following ruby code as a test:

class Plotlight
def get_message(a)
res = "Hello- from Ruby " << a
res
end

def swapcase(a)
res = a.downcase
res
end
end

Now, when running the method get_message("something"), things work great. However, when running something that has a reference to the standard library (swapcase in this example), it will return the error

$exception {"undefined method `downcase' for fooBAR:ClrString"} System.Exception {System.MissingMethodException}

Running the code through ir.exe works without any problems.

Do I need to make a reference to the library, and if I do, how do I do that?

Hope someone can help! Thank you very much.

Kind regards,
Marco

+2  A: 

Ruby strings have semantics that are incompatible with CLR strings. In particular, they're mutable. Interop between Ruby strings and CLR strings is not yet complete, so for now you'll need to explicitly cast the CLR System.String into a Ruby string object -- either in your C# code or in your Ruby code.

The simplest solution is to define swapcase like this:

def swapcase(a)
  String.new(a).downcase
end
Curt Hagenlocher
Alright, thank you very much Curt! This works great...