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

Intro to Ruby 2.0

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Intro to Ruby 2.0

Matt Aimonetti introduces Ruby 2.0 at SDRuby in Febr 2013.

Matt Aimonetti

March 07, 2013

Transcript

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

    Aimonetti Wednesday, March 13, 13
  2. #  before def  create(name,  opts={})    opts[:tos]  ||=  false  

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

                               timestamp:  Time.now)    puts  [name,  tos,  timestamp].inspect end Wednesday, March 13, 13
  4. 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
  5. create("Matt",  tos:  true,  location:            

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

                                     timestamp:  Time.now,                                    **rest)    puts  [name,  tos,  timestamp,                                                        rest].inspect end Wednesday, March 13, 13
  7. 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
  8. #  required  keyword  param def  new(name,        

               tos:  raise("TOS  is  required"),                  admin:  false) end Wednesday, March 13, 13
  9. #  Not  our  code class  Action    def  start  

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

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

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

     -­‐>  "just  do  it  better  with  Ruby!" Wednesday, March 13, 13
  13. 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
  14. Talk  =  Struct.new(:title,  :speaker) Talk.new("Ruby  2.0",  "Matt").to_h #  =>  {:title=>"Ruby

     2.0",              :speaker=>"Matt"}   Wednesday, March 13, 13
  15. Thread.        current.        thread_variable_set("@foo",  42)

    Thread. current. thread_variable_get("@foo") Thread.current.thread_variables Wednesday, March 13, 13

More Decks by Matt Aimonetti

Other Decks in Programming