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
Tweet

More Decks by Gabriel Fortuna

Other Decks in Programming

Transcript

  1. Ruby 2.0
    What’s  new?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  4. 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

    View full-size slide

  5. 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

    View full-size slide

  6. 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

    View full-size slide

  7. Deep Changes

    View full-size slide

  8. X
    BItmap Garbage
    Collection
    X
    X
    X
    X
    X

    View full-size slide

  9. 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

    View full-size slide

  10. 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

    View full-size slide

  11. X
    Backward
    Compatible With
    1.9
    X
    X
    X
    X
    X

    View full-size slide

  12. X
    require() speed
    improvements
    X
    X
    X
    X
    X

    View full-size slide

  13. X
    Keyword
    Arguments
    X
    X
    X
    X
    X

    View full-size slide

  14. Keyword
    Arguments
    def foo(foo: ‘bar’, baz: ‘qux’, **rest)
    # Do something
    end
    foo(baz: ‘qux’, foo: ‘frob’)
    Big Changes

    View full-size slide

  15. X
    Module
    Prepend
    X
    X
    X
    X
    X

    View full-size slide

  16. Module
    Prepend
    module IncludableModule
    def something; end
    end
    class MyClass
    prepend IncludableModule
    end
    Big Changes

    View full-size slide

  17. X
    Lazy
    Enumerators
    X
    X
    X
    X
    X

    View full-size slide

  18. 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

    View full-size slide

  19. X
    Tracepoint
    X
    X
    X
    X
    X

    View full-size slide

  20. Trace
    Point
    Big Changes
    OO  alterna*ve  to  set_trace_func
    trace = TracePoint.new(:raise) do |t|
    puts "Alert: Exception raised!"
    end
    trace.enable

    View full-size slide

  21. X
    Refinements
    X
    X
    X
    X
    X

    View full-size slide

  22. 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

    View full-size slide

  23. little Changes

    View full-size slide

  24. Literal
    Symbol lists
    sym_list = %i{eeny meeny miny moe}
    # => [:eeny, :meeny, :miny, :moe]
    Little Changes

    View full-size slide

  25. Binary
    Search
    haystack = (1..99999999)
    haystack.bsearch do |needle|
    needle == 12345
    end
    # => 12345
    Little Changes

    View full-size slide

  26. UTF-8
    On by Default
    #!/usr/bin/env ruby1.9
    #encoding: utf-8
    puts “✖ ✹ ✚ ✭”
    #!/usr/bin/env ruby-2.0
    puts “✖ ✹ ✚ ✭”
    Little Changes

    View full-size slide

  27. __Dir__
    keyword
    Little Changes
    Similar  in  func*onality  to  __FILE__
    Shows  absolute  path  to  file’s  directory
    No  more  clunky  File.dirname(__FILE__)

    View full-size slide

  28. .to_h
    Little Changes
    Follows  conven*on  started  by  .to_s,  to_i,  to_a,  etc
    Super  useful  for  conver*ng  Structs

    View full-size slide

  29. 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

    View full-size slide

  30. 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

    View full-size slide

  31. 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

    View full-size slide

  32. 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’

    View full-size slide

  33. Any
    Questions?
    @gee_forr
    [email protected]
    Thanks
    Code examples: https://github.com/gee-forr/whats_new_in_ruby_2.0

    View full-size slide