[Ironruby-core] Could you please teach a canonical style for writing the IronRuby hosting code.

はしもとけんいち ken1hasimoto at gmail.com
Sun Nov 29 09:04:46 EST 2009


Hello, I'm kenichi hashimoto.
I'm a Japanese. I don't write english well.

Now I have a question about a canonical style for writing the IronRuby
hosting code.

[BACKGROUND]
Now, I'm tring to host the IronRuby 1.0RC on C#.NET (Visual Studio 2008).
And, I have been trying to host it since IronRuby 0.5.
However, I haven't understood about how to write code in right style yet.

[QUESTION]
Could you please teach a canonical style for writing the IronRuby hosting code.

Now, I wrote below:

    static void Main(string[] args)
    {
        // create the IronRuby engine.
        ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
        var engine = runtime.GetEngine("rb");

        // create the scope and set the local variable from C#
        var scope = engine.CreateScope();
        scope.SetVariable("x", 123);

        // set the global variable from C#
        IronRuby.Ruby.GetExecutionContext(engine).DefineGlobalVariable("xxx",
789);

        // execute the script with the scope
        var source = engine.CreateScriptSourceFromString(@"puts ""x is
#{x}. $xxx is #{$xxx}."" ");
        source.Execute(scope);

        Console.ReadLine();
    }

Is it a canonical style?

Thank you.
B.R. Kenichi HASHIMOTO


More information about the Ironruby-core mailing list