SHARE
TWEET

Load Ruby Object

ForeverZer0 Sep 28th, 2011 169 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using IronRuby;
  2. using IronRuby.Builtins;
  3. using Microsoft.Scripting.Hosting;
  4.  
  5. // This sample targets the .NET 2.0 Framework, using IronRuby 1.0. If you are using IronRuby 1.1, it will be slightly different.
  6. // Make references to IronRuby.dll, IronRuby.Libraries.dll, Microsoft.Scripting.dll, and Micrsoft.Scripting.Core.dll
  7. // Although Microsoft.Dynamic.dll does not need referenced, it must be in the directory of the executing assembly
  8.  
  9. namespace RubySample
  10. {
  11.         public class SharpRubyForm
  12.         {
  13.                 private ScriptEngine _engine;
  14.                 private ScriptScope _scope;
  15.                
  16.                 private void InitializeRuby()
  17.                 {
  18.                         ScriptRuntime _runTime = Ruby.CreateRuntime();
  19.                         _engine = Ruby.GetEngine(_runTime);
  20.                         _scope = _engine.CreateScope();
  21.                 }
  22.                
  23.                 private object LoadRubyObject(string path)
  24.                 {
  25.                         _scope.SetVariable("path", path);
  26.                         return _engine.Execute(@"
  27.                         file = File.open(path, 'rb')
  28.                         object = Marshal.load(file)
  29.                         file.close
  30.                         return object", _scope);
  31.                 }
  32.         }      
  33. }
  34.  
  35.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top