Created
May 25, 2013 00:57
-
-
Save pjmagee/5647473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'uri' | |
| class Hello | |
| def initialize(users, manager) | |
| @users = users | |
| @manager = manager | |
| end | |
| def loop_users | |
| @users.each { |user| modify_user user } | |
| end | |
| def modify_user(user) | |
| user.user_name = user.user_name + " modified" | |
| end | |
| def google_query(query) | |
| uri = URI('http://google.com/') | |
| puts Net::HTTP.get(uri) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Program | |
| { | |
| private static readonly string ScriptsPath = Path.Combine(Environment.CurrentDirectory, "Scripts"); | |
| public static string PathFor(string script) | |
| { | |
| return Path.Combine(ScriptsPath, script); | |
| } | |
| public static void Main(string[] args) | |
| { | |
| IList<User> users = Builder<User>.CreateListOfSize(5).All().Build(); | |
| var manager = new MessageManager(); | |
| ScriptEngine engine = Ruby.CreateEngine(); | |
| var searchPaths = new[] | |
| { | |
| @"C:\Program Files (x86)\IronRuby 1.1\Lib\ironruby", | |
| @"C:\Program Files (x86)\IronRuby 1.1\Lib\ruby\1.9.1", | |
| @"C:\Program Files (x86)\IronRuby 1.1\Lib\ruby\site_ruby\1.9.1" | |
| }; | |
| engine.SetSearchPaths(searchPaths); | |
| foreach (var user in users) | |
| { | |
| Console.WriteLine(user.UserName); | |
| } | |
| try | |
| { | |
| engine.ExecuteFile(PathFor("hello.rb")); | |
| dynamic hello = engine.Runtime.Globals.GetVariable("Hello"); | |
| dynamic instance = engine.Operations.CreateInstance(hello, users, manager); | |
| engine.Operations.InvokeMember(instance, "loop_users"); | |
| engine.Operations.InvokeMember(instance, "google_query", "test"); | |
| } | |
| catch(Exception e) | |
| { | |
| Console.WriteLine(e.Message); | |
| } | |
| foreach (var user in users) | |
| { | |
| Console.WriteLine(user.UserName); | |
| } | |
| Console.Read(); | |
| } | |
| } | |
| public class User | |
| { | |
| public string UserName { get; set; } | |
| public string HostName { get; set; } | |
| } | |
| public class MessageManager | |
| { | |
| public void Say(string message) | |
| { | |
| Console.WriteLine(message); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment