Slide 1

Slide 1 text

Ruby 2.0 What’s  new?

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

History Big Changes Little Changes Install Deep Changes Eco System

Slide 4

Slide 4 text

History

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Install

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Deep Changes

Slide 10

Slide 10 text

X BItmap Garbage Collection X X X X X

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

X Backward Compatible With 1.9 X X X X X

Slide 15

Slide 15 text

X require() speed improvements X X X X X

Slide 16

Slide 16 text

Big Changes

Slide 17

Slide 17 text

X Keyword Arguments X X X X X

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

X Module Prepend X X X X X

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

X Lazy Enumerators X X X X X

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

X Tracepoint X X X X X

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

X Refinements X X X X X

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

little Changes

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Ecosystem

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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’

Slide 38

Slide 38 text

Now what

Slide 39

Slide 39 text

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