IronRuby for the.NET Developer Cory Foy - Cory Foy, LLC + + =
Hello, IronRuby!
Ruby
IronRuby
Ruby and WinForms
Ruby and Silverlight
History Ruby and.NET Ruby to.NET Ruby CLR Project RubyCLR All attempted to run Ruby on top of the CLR
History CLR 2.0 (.NET 3.0 and 3.5 were still CLR 2.0) No dynamic dispatch Everything had to be compiled Lots of magic, and shims CREDIT:
History alias alias_method_missing method_missing def method_missing(name, *params) alias_method_missing(name, *params) unless name == :Count create_ruby_instance_method(self.class, 'Count') do include 'System.Collections' ldarg_2 call 'static Marshal::ToClrObject(VALUE)' call 'ArrayList::get_Count()' call 'static Marshal::ToRubyNumber(Int32)' ret end self.Count end
History CLR 4.0 Dynamic keyword (C#) Calculator calc = GetCalculator(); int sum = calc.Add(1, 3); var calc = GetCalculator(); int sum = calc.Add(1, 3); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); dynamic calc = GetCalculator(); int sum = calc.Add(1, 3);
History Dynamic Keyword Calculator calc = GetCalculator(); int sum = calc.Add(1, 3);
History Dynamic Keyword var calc = GetCalculator(); int sum = calc.Add(1, 3);
History Dynamic Keyword object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res);
History Dynamic Keyword dynamic calc = GetCalculator(); int sum = calc.Add(1, 3);
History DLR Introduced in 2007 Set of libraries to assist language developers Still runs on the CLI, and can access the CLR Standardizes the implementation of dynamic languages on the CLI/CLR
History IronRuby John Lam hired by Microsoft in 2006 Announced in 2007 at MIX7 Goal to make Ruby a first-class citizen Completely rewritten to take advantage of the DLR
History DLR Dynamic Language Runtime (DLR) Common Language Runtime (CLR) Common Hosting Model Runtime Language Implementation
History Ruby Common Language Runtime Dynamic Language Runtime C# VB
WHY RUBY?
RUBY IS Love! CREDIT: ks/ ks/ CREDIT: CREDIT: onorail/ onorail/ CREDIT: stoms/ stoms/
CREDIT:
TYPE SAFETY STATIC CODE ANALYSIS COMPILER CATCHES ERRORS INTELLISENSE OBJECT GRAPHS DEBUGGING CODE SAFETY SEALED TYPES
TEST ALL THE FRICKIN’ TIME
CREDIT:
Metaprogramming All Classes Are Open Definitions are active All method calls have a receiver Classes are objects CREDIT: TOS/CHOCONANCY/
Duck Typing
Open Classes CREDIT: EON_OPEN_SIGN.JPG
Monkey Patching
Dynamism CREDIT: UEST/ /
method_missing CREDIT: TOS/TAITOH/ /
RubyGems Standardized Packaging System Central Repository for hosting packages Allows for installation and management of multiple installed versions
RubyGems THAT’S IT!
IronRuby Basics Installing Download Windows Installer ??? Profit!!!
IronRuby Basics..and what did we just install? bin - IronRuby executables (ir.exe, etc) lib - Helpers for including assemblies and other common tasks samples - Contains the Tutorial app and others silverlight - Contains the Silverlight Dynamic Languages SDK
IronRuby Basics..and, how the heck did it just do that? Common Language Runtime (CLR) Dynamic Language Runtime (DLR) Common Hosting Model Runtime Language Implementation ASTs Language Context CompilerRuntime Call sites Binders Rules Common Hosting Model ScriptRuntimeScriptEngine ScriptScopeScriptSource
Integration Calling.NET from IronRuby Calling IronRuby from.NET WinForms / WPF / Silverlight Cucumber / RSpec
Get Involved! Website Mailing List