AMIR BARYLKO                    IRON RUBY AND .NET                      A MATCH MADE IN                          HEAVEN   ...
WHO AM I?   • Architect   • Developer   • Mentor   • Great        cook   • The      one who’s entertaining you for the nex...
CONTACT AND MATERIALS   • Contact          me: amir@barylko.com, @abarylko   • Download: http://www.orthocoders.com/presen...
RUBY INTRO                                     Dynamic languages                                         Testing          ...
DYNAMIC LANGUAGES          High level          Dynamically typed          Runtime over compile time          Closures ...
.NET CLR           Iron Ruby                   DLR           CLRAmir Barylko - Iron Ruby and .NET              MavenThough...
DEVELOPERS TOOLBOX   • Make        your toolbox grow!   • The      right tool for the job   • Not       a replacement   • ...
WELCOME TO RUBY          Created in mid-90s by          Several implementations:           “Matz” Matsumoto in Japan    ...
RUBY FEATURES          Everything is an expression      Operator overloading,                                           ...
RUBY SUPPORT          Hundreds of books              Lots of great web sites:                                           ...
SET UP          Download IronRuby installer          Put the bin folder on the path          That’s it!Amir Barylko - I...
INTERACTIVE                             IRON RUBY SHELL      c:> ir.exe      > puts “hello”                   > x = 1.upto...
BASIC TYPES        Numbers          1.class => Fixnum          1.1.class => Float          (120**100).class => Bignum    ...
BASIC TYPES II   • Strings      he  + he => he he      “Thats right” => Thats right      He said “hi” => He said “hi”     ...
BASIC TYPES III      Arrays       a = [1, 5.5, “nice!”]       1 == a.first       1 == a[0]       nil == a[10]       a[1] ...
BASIC TYPES IV   • Hashes      h = {“one” => 1, 1 => “one”}      h[“one”] == 1      h[1] == “one”      h[“two”] == nil    ...
BASIC TYPES V       Symbols: constant names. No need to declare, guaranteed        uniqueness, fast comparison   :apple =...
CONTROL STRUCTURES          if           if count < 20             puts “need more”           elsif count < 40           ...
CONTROL STRUCTURES II        Statement modifiers         buy while need_more?         buy(5) if need_more?         buy unt...
CONTROL STRUCTURES III   • Case       case left            when 0..5              dont_buy_more            when 6..10     ...
METHODS        Simple          def play(movie_path)          ....          end        Default arguments          def pla...
METHODS II        Return value: the last expression evaluated, no need for         explicit return         def votes(vote...
METHODS III       No need also with arguments (but careful!! only if you know        what you are doing)         movie.pl...
RUBY INTRO II                                          Classes                                           Mixin            ...
CLASSES & OBJECTS       Initializer and instance variables         class Movie           def initialize(name)            ...
CLASSES & OBJECTS II        Attributes     class Movie       def initialize(name)         @name = name       end         ...
CODE ORGANIZATION        Code in files with .rb extension        Require movie will read movie.rb file and make its method...
CODE ORGANIZATION II       Relative to this file:         require File.join(File.dirname(__FILE__), media/movie)Amir Baryl...
MIXINS        What about module “instance methods”?        One of the greatest Ruby features!        You can define func...
ENUMERABLE        Enumerable mixin, from the standard library documentation:            The Enumerable mixin provides col...
ENUMERABLE II       It provides useful methods such as:             map             to_a             take_while       ...
EXAMPLES                                          rSpec                                    Enumerable Mixin               ...
RSPEC TESTING LIBRARY      require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.Mov...
EXTEND LIBRARY                 WITH METHOD MISSING      require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibra...
SIMPLE WEB WITH SINATRA      require rubygems      require sinatra      require haml      require singleton      require F...
BDD WITH CUCUMBER      Feature: Addition      	    In order to make my library grow      	    As a registered user      	 ...
CUCUMBER STEPS      require File.dirname(__FILE__) + "/../../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLi...
DSL I                                    RAKE   desc "Builds the project"   task :build do   	 call_target msbuild_cmd, :b...
DSL II                        CRON - WHENEVER    every 10.minutes do       runner "MyModel.some_process"       rake "my:ra...
QUESTIONS?                               (Don’t be shy)Thursday, January 13, 2011
CONTACT AND MATERIALS   •   Contact me: amir@barylko.com, @abarylko   •   Download: http://www.orthocoders.com/presentatio...
ONLINE RESOURCES        IronRuby: http://ironruby.net/        The Ruby Bible (a.k.a. Pickaxe): http://ruby-doc.org/docs/...
Upcoming SlideShare
Loading in...5
×

Codemash-iron-ruby-match-made-in-heaven

588

Published on

Presenta

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
588
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Codemash-iron-ruby-match-made-in-heaven

  1. 1. AMIR BARYLKO IRON RUBY AND .NET A MATCH MADE IN HEAVEN CODEMASH JAN 2011Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  2. 2. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next while!Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  3. 3. CONTACT AND MATERIALS • Contact me: amir@barylko.com, @abarylko • Download: http://www.orthocoders.com/presentations.Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  4. 4. RUBY INTRO Dynamic languages Testing IRB ConstructsAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  5. 5. DYNAMIC LANGUAGES  High level  Dynamically typed  Runtime over compile time  Closures  Reflection  Platform independentAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  6. 6. .NET CLR Iron Ruby DLR CLRAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  7. 7. DEVELOPERS TOOLBOX • Make your toolbox grow! • The right tool for the job • Not a replacement • Combine strengths • Problem solvingAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  8. 8. WELCOME TO RUBY  Created in mid-90s by  Several implementations: “Matz” Matsumoto in Japan MRI, YARB, JRuby  Smalltalk, Perl influences  Totally free!!  Dynamic typing  Object Oriented  Automatic memory managementAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  9. 9. RUBY FEATURES  Everything is an expression  Operator overloading, flexible syntax  Metaprogramming  Powerful standard library  Closures  Garbage collection  ExceptionsAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  10. 10. RUBY SUPPORT  Hundreds of books  Lots of great web sites: basecamp, twitter, 43  User conferences all over things, hulu, scribd, the world slideshare, Justin.tv  Active community (you can  Lots of web frameworks create a conf in your own inspired by Ruby on Rails city and top Ruby coders will go there to teach others, invite them and see)Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  11. 11. SET UP  Download IronRuby installer  Put the bin folder on the path  That’s it!Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  12. 12. INTERACTIVE IRON RUBY SHELL c:> ir.exe > puts “hello” > x = 1.upto(5).to_a hello => [1, 2, 3, 4, 5] => nil > x.join > "Hello World! " * 2 => "12345" => "Hello World! Hello World!" > (1..10).inject([]) { |a, i| a << i } > ((1 + 5) * 3) ** 2 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] => 324Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  13. 13. BASIC TYPES  Numbers 1.class => Fixnum 1.1.class => Float (120**100).class => Bignum 3.times {puts “he “}Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  14. 14. BASIC TYPES II • Strings he + he => he he “Thats right” => Thats right He said “hi” => He said “hi” “He said “hi”” => He said “hi” “1 + 1 is #{1+1}” => 1 + 1 is 2 "#{Ho! *3}Merry Christmas" =>Ho! Ho! Ho! Merry ChristmasAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  15. 15. BASIC TYPES III  Arrays a = [1, 5.5, “nice!”] 1 == a.first 1 == a[0] nil == a[10] a[1] = 3.14 a.each {|elem| puts elem} a.sortAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  16. 16. BASIC TYPES IV • Hashes h = {“one” => 1, 1 => “one”} h[“one”] == 1 h[1] == “one” h[“two”] == nil h.keys == [“one”, 1] (or is it [1, “one”] ?) h.values == [“one”, 1] (or is it [1, “one”] ?) h[“one”] = 1.0Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  17. 17. BASIC TYPES V  Symbols: constant names. No need to declare, guaranteed uniqueness, fast comparison :apple == :apple :orange != :banana [:all, :those, :symbols] {:ca => “Canada”, :ar => “Argentina”, :es => “Spain”}Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  18. 18. CONTROL STRUCTURES  if if count < 20 puts “need more” elsif count < 40 puts “perfect” else puts “too many” end  while while count < 100 && need_more buy(1) endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  19. 19. CONTROL STRUCTURES II  Statement modifiers buy while need_more? buy(5) if need_more? buy until left == 0 buy unless left < 5Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  20. 20. CONTROL STRUCTURES III • Case case left when 0..5 dont_buy_more when 6..10 buy(1) when 10..100 buy(5) endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  21. 21. METHODS  Simple def play(movie_path) .... end  Default arguments def play(movie_path, auto_start = true, wrap = false) .... endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  22. 22. METHODS II  Return value: the last expression evaluated, no need for explicit return def votes(voted, num_votes) voted && num_votes || nil end  No need for parenthesis on call without arguments (same syntax to call a method and a field) buy() == buy movie.play() == movie.playAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  23. 23. METHODS III  No need also with arguments (but careful!! only if you know what you are doing) movie.play “Pulp fiction”, false, trueAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  24. 24. RUBY INTRO II Classes Mixin EnumerableAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  25. 25. CLASSES & OBJECTS  Initializer and instance variables class Movie def initialize(name) @name = name end def play puts %Q{Playing “#{@name}”. Enjoy!} end end m = Movie.new(“Pulp fiction”) m.play => Playing “Pulp fiction”. Enjoy!Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  26. 26. CLASSES & OBJECTS II  Attributes class Movie def initialize(name) @name = name end } def name # attr_reader :name @name end # attr_accessor :name def name=(value) # attr_writter :name @name = value end end m = Movie.new(Brazil).name = “Pulp fiction”Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  27. 27. CODE ORGANIZATION  Code in files with .rb extension  Require movie will read movie.rb file and make its methods available to the current file  Require media/movie will read file from media dir relative to the current working dir $LOAD_PATH << media require movieAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  28. 28. CODE ORGANIZATION II  Relative to this file: require File.join(File.dirname(__FILE__), media/movie)Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  29. 29. MIXINS  What about module “instance methods”?  One of the greatest Ruby features!  You can define functions in Modules, and get them added to your classes.  Great code reuse,  Multiple inheritance alternative.  Code organizationAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  30. 30. ENUMERABLE  Enumerable mixin, from the standard library documentation: The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collectionAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  31. 31. ENUMERABLE II  It provides useful methods such as:  map  to_a  take_while  count  injectAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  32. 32. EXAMPLES rSpec Enumerable Mixin missing_method Sinatra BDD Cucumber DSLAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  33. 33. RSPEC TESTING LIBRARY require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" require rubygems require spec include MavenThought::MovieLibrary describe Library do it "should be created empty" do lib = Library.new lib.contents.should be_empty end it "should add an element" do lib = Library.new m = Movie.new Blazing Saddles lib.add m lib.contents.should include(m) lib.contents.count.should == 1 end endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  34. 34. EXTEND LIBRARY WITH METHOD MISSING require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" require rubygems include MavenThought::MovieLibrary # Extend library to use method missing to add find_by class Library def method_missing(m, *args) if m.id2name.include?( "find_by" ) field = m.id2name.sub /find_by_/, "" contents.find_all( lambda{ |m| m.send(field) == args[0] } ) else super end end end l = Library.new l.add Movie.new(Blazing Saddles, System::DateTime.new(1972, 1, 1)) l.add Movie.new(Spaceballs, System::DateTime.new(1984, 1, 1)) puts "Found the movie #{l.find_by_title Spaceballs}" puts "Found the movie #{l.find_by_release_date System::DateTime.new(1972, 1, 1)}"Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  35. 35. SIMPLE WEB WITH SINATRA require rubygems require sinatra require haml require singleton require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" include MavenThought::MovieLibrary class Library include Singleton end # index get / do @movies = Library.instance.contents haml :index end # create post / do m = Movie.new(params[:title]) Library.instance.add m redirect / endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  36. 36. BDD WITH CUCUMBER Feature: Addition In order to make my library grow As a registered user I want to add movies to the library Scenario: Add a movie Given I have an empty library When I add the following movies: | title | release_date | | Blazing Saddles | Feb 7, 1974 | | Young Frankenstein | Dec 15, 1974 | | Spaceballs | Jun 24, 1987 | Then The library should have 3 movies And "Blazing Saddles" should be in the list with release date "Feb 7, 1974" And "Young Frankenstein" should be in the list with release date "Dec 15, 1974" And "Spaceballs" should be in the list with release date "Jun 24, 1987"Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  37. 37. CUCUMBER STEPS require File.dirname(__FILE__) + "/../../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" include MavenThought::MovieLibrary Given /^I have an empty library$/ do @lib = Library.new end When /^I add the following movies:$/ do |table| table.hashes.each do |row| movie = Movie.new row[:title], System::DateTime.parse(row[:release_date]) @lib.add movie end end Then /^The library should have (.*) movies$/ do |count| @lib.contents.count.should == count.to_i end Then /^"([^"]*)" should be in the list with release date "([^"]*)"$/ do |title, release| @lib.contents.find( lambda { |m| m.title == title and m.release_date == System::DateTime.parse(release) } ).should_not be_nil endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  38. 38. DSL I RAKE desc "Builds the project" task :build do call_target msbuild_cmd, :build end desc "Rebuild the application by cleaning and then building" task :rebuild => [:clean, :build] desc "Runs all the tests" task :test => ["test:all"]Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  39. 39. DSL II CRON - WHENEVER every 10.minutes do runner "MyModel.some_process" rake "my:rake:task" command "/usr/bin/my_great_command" end every 2.days, :at => 4:30am do command "/usr/bin/my_great_command" endAmir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  40. 40. QUESTIONS? (Don’t be shy)Thursday, January 13, 2011
  41. 41. CONTACT AND MATERIALS • Contact me: amir@barylko.com, @abarylko • Download: http://www.orthocoders.com/presentations.Amir Barylko - RoR Training MavenThought Inc. - June 2010Thursday, January 13, 2011
  42. 42. ONLINE RESOURCES  IronRuby: http://ironruby.net/  The Ruby Bible (a.k.a. Pickaxe): http://ruby-doc.org/docs/ProgrammingRuby/  Ruby language site: http://www.ruby-lang.org  rSpec: http://rspec.info/  Sinatra: http://www.sinatrarb.com/  Cucumber: http://cukes.info/  Rake: http://rake.rubyforge.org/Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Jan 2011Thursday, January 13, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×