So far here’s what I’ve done, and I’m not really sure it’s meant to work, but well, better try something than doing nothing. I’ve added a Ruby class in my Winform project and it looks like this:
class My_Ruby_Class
def initialize(number)
@number = number
change_number()
end
def change_number
@number*= 2
end
def get_number
return @number
end
end
So later in my c# MainForm.cs I type:
namespace ruby_in_dotNet_test_01
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
int number = 2;
My_Ruby_Class test = new My_Ruby_Class(number);
int number2 = test.get_number();
}
}
}
Very interestingly the intellisense seems to detect my ruby class and even helps me to fill the areas as I type, so it seems to me I’m on the right path. However it doesn’t compile. The compiler error seems to be related to a missing type or namespace. I tried to surround my ruby class between the ‘module ruby_in_dotNet_test_01’ block but no success.
I’m confused, maybe there’s only one small detail I’m not doing properly, or maybe this approach isn’t meant to work at all?
Basically what you are trying to do won’t work out-of-the box (define ruby code in a file and directly use it from C# and still get strong typing and Intellisense). Did you forget that Ruby is a weakly typed language?
You could use IronRuby to call ruby code from C#. Here’s a
step-by-step articleillustrating the process. And here’s ascreencastyou could watch.