Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created October 22, 2009 08:00
Show Gist options
  • Save jschementi/215817 to your computer and use it in GitHub Desktop.
Save jschementi/215817 to your computer and use it in GitHub Desktop.
IronRuby and C# 4 "dynamic"
using System;
using IronRuby;
public class dynamic_demo {
static void Main() {
var rb = Ruby.CreateEngine();
rb.ExecuteFile("mock.rb");
dynamic globals = rb.Runtime.Globals;
// Call the Ruby "Mock" class constructor
dynamic m = globals.Mock.@new();
//The Ruby Mock instance dynamically responds to any member that is requested of it
Console.WriteLine(
m.the_csharp_compiler_cannot_possbily_know_this_method_exists_at_compile_time()
);
}
}
class Mock
# instances of this class will dynamically respond to any method
def method_missing(method_name)
["hello world", Math::PI][rand(2)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment