Intro to Ruby 2.0

Intro to Ruby 2.0

Matt Aimonetti introduces Ruby 2.0 at SDRuby in Febr 2013.

C69521d6e22fc0bbd69337ec8b1698df?s=128

Matt Aimonetti

March 07, 2013
Tweet

Transcript

  1. ruby 2.0 San Diego Ruby - March 2013 - Matt

    Aimonetti Wednesday, March 13, 13
  2. Barney Stinson approved Wednesday, March 13, 13

  3. Safe for Human Consumption Wednesday, March 13, 13

  4. horse meat free Wednesday, March 13, 13

  5. Ruby is 20 years old! Wednesday, March 13, 13

  6. what you really need to know Wednesday, March 13, 13

  7. Migration from Ruby 1.9 is trivial Wednesday, March 13, 13

  8. Ruby 1.8 reaches its end of life in June Wednesday,

    March 13, 13
  9. Performance improvement Wednesday, March 13, 13

  10. favorite Ruby Wednesday, March 13, 13

  11. less new features Wednesday, March 13, 13

  12. The new REE Wednesday, March 13, 13

  13. Heroku support Wednesday, March 13, 13

  14. Ruby 2.1 scheduled for Xmas 2013 Wednesday, March 13, 13

  15. getting started Wednesday, March 13, 13

  16. rvm rbenv chruby Wednesday, March 13, 13

  17. libyaml (recent) openssl Dependencies you might need to resolve Wednesday,

    March 13, 13
  18. new in 2.0 Wednesday, March 13, 13

  19. default code encoding Wednesday, March 13, 13

  20. keyword arguments Wednesday, March 13, 13

  21. #  before def  create(name,  opts={})    opts[:tos]  ||=  false  

     opts[:timestamp]  ||=  Time.now end Wednesday, March 13, 13
  22. #  now def  create(name,  tos:  false,        

                               timestamp:  Time.now)    puts  [name,  tos,  timestamp].inspect end Wednesday, March 13, 13
  23. create("Matt") #  -­‐>  ["Matt",  false,          

         2013-­‐03-­‐06  16:34:49  -­‐0800] create("Matt",  timestamp:  Time.now  -­‐  42) #  -­‐>  ["Matt",  false,                2013-­‐03-­‐06  16:34:07  -­‐0800] create("Matt",  tos:  true,  location:                                                                    "SDRuby") #  -­‐>  unknown  keyword:  location   (ArgumentError) Wednesday, March 13, 13
  24. create("Matt",  tos:  true,  location:            

                                                           "SDRuby") #  -­‐>  unknown  keyword:  location   (ArgumentError) Wednesday, March 13, 13
  25. #  more  flexible  API   def  create(name,  tos:  false,  

                                     timestamp:  Time.now,                                    **rest)    puts  [name,  tos,  timestamp,                                                        rest].inspect end Wednesday, March 13, 13
  26. create("Matt") #  -­‐>  ["Matt",  false,          

               2013-­‐03-­‐06  16:30:29  -­‐0800,  {}] create("Matt",  timestamp:  Time.now  -­‐  42) #  -­‐>  ["Matt",  false,                      2013-­‐03-­‐06  16:29:47  -­‐0800,  {}] create("Matt",  tos:  true,                                location:  "SDRuby") #  -­‐>  ["Matt",  true,  2013-­‐03-­‐06  16:30:29   -­‐0800,  {:location=>"SDRuby"}] Wednesday, March 13, 13
  27. #  required  keyword  param def  new(name,        

               tos:  raise("TOS  is  required"),                  admin:  false) end Wednesday, March 13, 13
  28. new("Matt",  tos:  false) #-­‐>  ["Matt",  false,  false] new("Matt") #-­‐>  TOS

     is  required  (RuntimeError) Wednesday, March 13, 13
  29. module #prepend Wednesday, March 13, 13

  30. #  Not  our  code class  Action    def  start  

         "just  do  it"    end end Wednesday, March 13, 13
  31. #  The  module  including  our   modifying  code module  RubyIt

       def  start        super  +  "  better  with  Ruby!"    end end Wednesday, March 13, 13
  32. module  RubyIt    def  start        super  +

     "  better  with  Ruby!"    end end Wednesday, March 13, 13
  33. class  Action    prepend  RubyIt end   p  Action.new.start #

     -­‐>  "just  do  it  better  with  Ruby!" Wednesday, March 13, 13
  34. lazy streams Wednesday, March 13, 13

  35. require  'date'   #  Print  the  next  13  Friday  the

     13th. puts  (Date.new(2013)..Date.new(9999))    .lazy    .select{|d|  d.day  ==  13  &&  d.friday?}    .first(13) Wednesday, March 13, 13
  36. 2013-09-13 2013-12-13 2014-06-13 2015-02-13 2015-03-13 2015-11-13 2016-05-13 2017-01-13 2017-10-13 2018-04-13

    2018-07-13 2019-09-13 2019-12-13 Wednesday, March 13, 13
  37. to_h convention Wednesday, March 13, 13

  38. Talk  =  Struct.new(:title,  :speaker) Talk.new("Ruby  2.0",  "Matt").to_h #  =>  {:title=>"Ruby

     2.0",              :speaker=>"Matt"}   Wednesday, March 13, 13
  39. %i{foo  bar  baz} [:foo,  :bar,  :baz] Wednesday, March 13, 13

  40. tracepoint support Wednesday, March 13, 13

  41. GC/misc optimization Wednesday, March 13, 13

  42. more... Wednesday, March 13, 13

  43. caller_locations caller(start, length) Wednesday, March 13, 13

  44. dtrace support Wednesday, March 13, 13

  45. infamous refinements Wednesday, March 13, 13

  46. Array / Range binary search Wednesday, March 13, 13

  47. Kernel.inspect != Kernel.to_s Wednesday, March 13, 13

  48. String#b "déjà  vu".b Wednesday, March 13, 13

  49. Thread.        current.        thread_variable_set("@foo",  42)

    Thread. current. thread_variable_get("@foo") Thread.current.thread_variables Wednesday, March 13, 13
  50. https://github.com/ruby/ ruby/blob/ruby_2_0_0/NEWS Wednesday, March 13, 13

  51. @merbist http://matt.aimonetti.net Wednesday, March 13, 13