IronRuby RCã§ã®ãã¹ãã£ã³ã°
IronRubyã¯Î±æ代ããå¼ã£ã¦ãã¾ãããããã¼ã¸ã§ã³ãä¸ãããã³ã«ãã¹ãã£ã³ã°æ¹æ³ãå¤æ´ããã¦ãã¾ãããRCã«ãªã£ãã®ã§ããããæçµçã ã¨æãããã®ã§ãããã©ã¼ãªãã§ããã(^^;
ã¦ãã¨ã¼ãªrubyã®ã¯ã©ã¹ã
class Foo def bar puts 'baz' end def add(x, y) x + y end def sub(x, y) x - y end end
ãããC#ããå¼ã³åºãã¦ã¿ã¾ãã
using System; using System.Collections.Generic; using System.Linq; using System.Text; using IronRuby.Hosting; namespace IronRubySample { class Program { static void Main(string[] args) { // rubyã«ããã¯ã©ã¹å®ç¾© var path = "Foo.rb"; // rubyã¹ã¯ãªãããå®è¡ var ir = IronRuby.Ruby.CreateRuntime(); ir.ExecuteFile(path); // ã¯ã©ã¹ãªãã¸ã§ã¯ããåå¾ var fooClass = ir.Globals.GetVariable("Foo"); // ã¤ã³ã¹ã¿ã³ã¹ã®çæ dynamic foo = ir.Operations.CreateInstance(fooClass); // ã¡ã½ãããå¼ã³åºã foo.bar(); Console.WriteLine(foo.add(10, 20)); Console.WriteLine(foo.sub(10, 20)); } } } /* çµæ baz 30 -10 */
dynamicã®ãããã§ãçµæ§ãã£ãããããããã«ãªãã¾ãããã