Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- using Microsoft.Scripting;
- using Microsoft.Scripting.Hosting;
- using IronRuby;
- namespace IronRubyTest1
- {
- public class Human
- {
- protected string GetInternalCondition()
- {
- return "all good";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- const string RubyCode = @"
- class Doctor < IronRubyTest1::Human
- def check_condition()
- puts 'Condition: ' + get_internal_condition()
- end
- end";
- ScriptRuntime runtime = Ruby.CreateRuntime();
- ScriptEngine engine = Ruby.GetEngine(runtime);
- ScriptScope scope = engine.CreateScope();
- //让 DLR 载入包含 Human 类的 Assembly
- runtime.LoadAssembly(Assembly.GetExecutingAssembly());
- engine.Execute(RubyCode, scope); //执行 Ruby 代码
- dynamic globals = engine.Runtime.Globals;
- dynamic house = globals.Doctor.@new(); //创建 Doctor 的实例
- house.check_condition();
- Console.WriteLine("Press any key to close...");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement