Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in Ruby 2.0

What's new in Ruby 2.0

A walkthrough of what' new in Ruby 2.0 at the March 2013 Ruby On Beer in Johannesburg

Gabriel Fortuna

March 21, 2013

More Decks by Gabriel Fortuna

Other Decks in Programming


  1. Ruby 2.0 What’s  new?

  2. About me @gee_forr Internet Solutions #rubyOnBeer I <3 Ruby

  3. History Big Changes Little Changes Install Deep Changes Eco System

  4. History

  5. Feb 24 1993 Dec 21 1995 Start  of  Xmas  Tradi.on

    Ruby’s History Language  starts  gaining   serious  trac.on I  want  a  language  more   powerful  than  Perl  and   more  OO  than  Python First  public  release 0.95 Dec 25 1996 1.0 1.2 Dec 1998 1.4 Aug 1999 1.6 Sep 2000 1.8 Aug 2003 Dec 13 2005 Rails  arrives  on  the   scene.  Arguably  the   start  of  Ruby’s  rise. Dec 2007 Language  hits  the  big   .me. 1.9
  6. Start  of  Xmas  Tradi.on Ruby’s History nguage  starts  gaining  

    rious  trac.on 1.8 Aug 2003 Dec 13 2005 Rails  arrives  on  the   scene.  Arguably  the   start  of  Ruby’s  rise. Dec 2007 Language  hits  the  big   .me. 1.9 Feb 24 2013 2.0
  7. Install

  8. The one true way The one true way ✦Update  RVM

    ✦rvm install ruby-2.0.0 ✦Update  rbenv ✦rbenv install 2.0.0-p0 RVM RBENV
  9. Deep Changes

  10. X BItmap Garbage Collection X X X X X

  11. None
  12. Heap based M&S Ruby  structures  are  divided  in  2  

      halves,  data  and  flags.  Each   structure  has  its  own  flag.  Mark   phase  trawls  through  heap  and   updates  FL_MARK  flag  in  every   object 1.9 GC RString diagram from: http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0
  13. Bitmap marking All  mark  flags  for  heap  move  to  

    single  dedicated  data  structure.   1  for  In  Use,  0  for  Collectable. Flag  not  wriMen  to  data   structure,  much  more  friendly   to  copy-­‐on-­‐write 2.0 GC Heap diagram from: http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0
  14. X Backward Compatible With 1.9 X X X X X

  15. X require() speed improvements X X X X X

  16. Big Changes

  17. X Keyword Arguments X X X X X

  18. Keyword Arguments def foo(foo: ‘bar’, baz: ‘qux’, **rest) # Do

    something end foo(baz: ‘qux’, foo: ‘frob’) Big Changes
  19. X Module Prepend X X X X X

  20. Module Prepend module IncludableModule def something; end end class MyClass

    prepend IncludableModule end Big Changes
  21. X Lazy Enumerators X X X X X

  22. Lazy Enumerators to_infinity = (0..Float::Infinity) beyond = to_infinity.lazy.select do |n|

    num % 42 == 0 end 100.times do { |n| puts beyond.next } Big Changes
  23. X Tracepoint X X X X X

  24. Trace Point Big Changes OO  alterna*ve  to  set_trace_func trace =

    TracePoint.new(:raise) do |t| puts "Alert: Exception raised!" end trace.enable
  25. X Refinements X X X X X

  26. Refinements * Big Changes Localised  and  contained  monkey  patching Module

    MyString refine String do def palindrome? self == self.reverse end end end using MyString # Monkey patch now active for context
  27. little Changes

  28. Literal Symbol lists sym_list = %i{eeny meeny miny moe} #

    => [:eeny, :meeny, :miny, :moe] Little Changes
  29. Binary Search haystack = (1..99999999) haystack.bsearch do |needle| needle ==

    12345 end # => 12345 Little Changes
  30. UTF-8 On by Default #!/usr/bin/env ruby1.9 #encoding: utf-8 puts “✖

    ✹ ✚ ✭” #!/usr/bin/env ruby-2.0 puts “✖ ✹ ✚ ✭” Little Changes
  31. __Dir__ keyword Little Changes Similar  in  func*onality  to  __FILE__ Shows

     absolute  path  to  file’s  directory No  more  clunky  File.dirname(__FILE__)
  32. .to_h Little Changes Follows  conven*on  started  by  .to_s,  to_i,  to_a,

     etc Super  useful  for  conver*ng  Structs
  33. Little Changes CGI  is  now  HTML5  compa*ble net/hLp  supports  Server

     Name  Indica*on  (SNI) Grab Bag Zlib  runs  outside  of  the  Global  Interpreter  Lock Unused  variables  can  be  prepended  with  _  to  avoid  warnings
  34. Ecosystem

  35. Ecosystem Start  of  support  for  stdlib  gems No  more  out

     of  place  requires!  MOAR  BUNDLAR! RubyGems 2.0 Searching  is  remote  by  default Metadata  through  Gem::Specifica*on#metadata Simplified  --document/--no-document No  more  --no-rdoc --no-ri mantra
  36. Ecosystem Supports  Ruby  2.0 Supports  Rubygems  2.0 Bundler 1.3(.1) Supports

     Rails  4.0 Support  for  signed  gems! install and update up  to  150x  faster
  37. EcoSystem Ruby  2.0  is  the  official  preferred  ruby  version Beta

     released  1  day  a_er  Ruby  2.0 Rails 4.0 beta gem install rails --version 4.0.0.beta1 --no-document gem ‘rails’, ‘4.0.0-beta1’
  38. Now what

  39. Any Questions? @gee_forr GEE.FORR@GMAIL.COM Thanks Code examples: https://github.com/gee-forr/whats_new_in_ruby_2.0