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. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. Keyword Arguments def foo(foo: ‘bar’, baz: ‘qux’, **rest) # Do

    something end foo(baz: ‘qux’, foo: ‘frob’) Big Changes
  7. 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
  8. Trace Point Big Changes OO  alterna*ve  to  set_trace_func trace =

    TracePoint.new(:raise) do |t| puts "Alert: Exception raised!" end trace.enable
  9. 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
  10. Literal Symbol lists sym_list = %i{eeny meeny miny moe} #

    => [:eeny, :meeny, :miny, :moe] Little Changes
  11. UTF-8 On by Default #!/usr/bin/env ruby1.9 #encoding: utf-8 puts “✖

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

     absolute  path  to  file’s  directory No  more  clunky  File.dirname(__FILE__)
  13. 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
  14. 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
  15. 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
  16. 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’