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

Ruby2.5.0 overview

Ruby2.5.0 overview

Ruby2.5.0のリリースを目前に控え、変更点をLT用にまとめ共有した。

ishikawa ryu

April 19, 2018
Tweet

More Decks by ishikawa ryu

Other Decks in Technology

Transcript

  1. 5SZJU cd path/to/sandbox && mkdir locale wget https://cache.ruby-lang.org/pub/ruby/2.5/ ruby-2.5.0-preview1.tar.gz tar

    xvzf https://cache.ruby-lang.org/pub/ruby/2.5/ ruby-2.5.0-preview1.tar.gz cd ruby-2.5.0-preview1 ./configure —prefix=/path/to/sandbox/local make sudo make install cd ../local ./bin/ruby -v #=> 2.5.0preview1
  2. ,FSOFMZJFME@TFMG # Ҿ਺ʹࣗ෼ࣗ਎ΛͱΓɺϒϩοΫҾ਺ΛฦΓ஋ͱ͢Δ(mapͬΆ͍) 2.yield_self { |n| n * 10 }

    #=> 20 # tap͸ϒϩοΫͷத਎Λฦ͢Θ͚Ͱ͸ͳ͍ 2.tap { |n| n * 10 } #=> 2 # Ϩγʔόͦͷ΋ͷΛtap಺Ͱॻ͖׵͑ΔΑ͏ͳॲཧ͸ಉ݁͡ՌʹͳΔ [].tap { |arr| arr << 1 << 2 << 3 } [].yield_self { |arr| arr << 1 << 2 << 3 }
  3. ,FSOFMZJFME@TFMG require 'rest-client' require 'uri' require 'json' payment_id = 'hogehoge'

    endpoint = URI::Generic.build( # 1. endpointͷ౔୆࡞੒ scheme: 'http', # host: 'api.example.com', # path: "/api/v1/payments/#{payment_id}", # port: 3000 # ).to_s # response = RestClient.get(endpoint) # 2. ϦΫΤετ౤͛Δ response_body = JSON.parse(response.body) # 3. ϨεϙϯεΛjsonͱͯ͠ղऍ͢Δ # puts response_body #=> { version: "1.0.0", response: { message: "..." } }
  4. ,FSOFMZJFME@TFMG require 'rest-client' require 'uri' require 'json' payment_id = 'hogehoge'

    response_body = URI::Generic.build( # 1. endpointͷ౔୆࡞੒ scheme: 'http', # host: 'api.example.com', # path: "/api/v1/payments/#{payment_id}", # port: 3000 # ).to_s # .yield_self { |endpoint| RestClient.get(endpoint) } # 2. ϦΫΤετ౤͛Δ .yield_self { |response| JSON.parse(response.body) } # 3. ղऍ͢Δ # puts response_body #=> { version: "1.0.0", response: { message: "..." } }
  5. ,FSOFMZJFME@TFMG res = RestClient.get("/users/current") user = JSON.parse(res.body) user_id = user['id']

    res = RestClient.get("/users/#{user_id}/friends") friends = JSON.parse(res.body) f_id = friends.last['id'] res = RestClient.get("/users/#{f_id}/profile") profile = JSON.parse(res.body)
  6. ,FSOFMZJFME@TFMG profile = RestClient.get("/users/current") .yield_self { |res| JSON.parse(res.body) }
 .yield_self

    { |user| user['id'] }
 .yield_self { |user_id| RestClient.get("/users/#{user_id}/ friends") } .yield_self { |res| JSON.parse(res.body) } .yield_self { |friends| friends.last['id'] } .yield_self { |f_id| RestClient.get(“/users/#{f_id}/ profile”) } .yield_self { |res| JSON.parse(res.body) }