tags:

views:

92

answers:

1

I'm attempting to run an IronRuby script from C#:

var runtime = IronRuby.Ruby.CreateRuntime();                  
runtime.ExecuteFile("ruby/foo.rb");

foo.rb starts with a "require:"

#!/usr/bin/env ruby
require 'bar'

When I try this, I get an exception stating "no such file to load -- bar." The file "bar.rb" and the directory "bar" are both present in the "ruby" directory.

So, how do I execute a ruby script that requires other ruby files? I'm targeting .Net 3.5.

+1  A: 

Use the ScriptEngine instead and add your ruby code files directory to the search path:

var engine = IronRuby.Ruby.CreateEngine();

var paths = engine.GetSearchPaths().ToList();
paths.Add(@"C:\Path\To\My\Ruby\Files"); // Add the path to your ruby code files
engine.SetSearchPaths(paths);

engine.ExecuteFile("ruby/foo.rb");
Shay Friedman
Thanks! This works with a minor change, which I made above.
James Sulak