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

Ruby 2 and Rails 4

Ruby 2 and Rails 4

「Ruby 2.0 & Rails 4.0先取りセミナー」の講演資料
(2012/11/21, Web CAT Studioさん主催)
http://atnd.org/events/33996

Akira Matsuda

November 21, 2012
Tweet

More Decks by Akira Matsuda

Other Decks in Programming

Transcript

  1. Ruby 2.0 & Rails 4.0
    দా ໌ (@a_matsuda)

    View Slide

  2. whoami
    GitHub: amatsuda
    Twitter: @a_matsuda

    View Slide

  3. View Slide

  4. https://forkwell.com/
    ϑϦʔϥϯεͷࣾ֎औక໾ (Ṗ)
    pull requestʹίϝϯτॻ͘ͻͱ

    View Slide

  5. before

    View Slide

  6. ůŢ
    RubyKaigiʹࢀՃͨ͜͠ͱ͋Δਓʁ
    Railsษڧձ@౦ژʹࢀՃͨ͜͠ͱ͋Δਓʁ
    Asakusa.rbʹࢀՃͨ͜͠ͱ͋Δਓʁ

    View Slide

  7. begin

    View Slide

  8. ຊ೔ͷ͓୊
    2ͭͷʮϝδϟʔόʔδϣϯΞοϓʯ

    View Slide

  9. ϝδϟʔόʔδϣϯΞοϓʂ
    Ruby: 1.9.3 => 2.0.0
    Rails: 3.2.9 => 4.0.0

    View Slide

  10. ۭલͷ
    ϝδϟʔόʔδϣϯΞοϓظʂ
    Ruby 2.0
    Rails 4.0
    Rake 10.0
    RubyGems 2.0
    RDoc 4.0
    RSpec 3.0
    Sprockets 3.0
    Capybara 2.0
    Rubinius 2.0
    ...

    View Slide

  11. ϝδϟʔόʔδϣϯΞοϓظ
    ࣌୅ͷస׵఺
    ৺ػҰస
    ࢀೖͷνϟϯεʂ

    View Slide

  12. Ruby 2.0

    View Slide

  13. Ruby 2.0
    (Matzͷ)௕೥ͷ൵ئ
    2001೥ͷୈ1ճRubyConfͷΩʔϊʔτͰ
    Matz͕طʹRuby 2.0ʹݴٴ
    ʮֆʹඳ͍ͨṷʯʮ೩ྉʯʮχϯδϯʯ
    ʮPerl 6ʯ

    View Slide

  14. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ (1993/2/24)
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2013೥02݄ 2.0

    View Slide

  15. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6

    View Slide

  16. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8

    View Slide

  17. ͜ͷࠒͷόʔδϣχϯάϧʔϧ
    ۮ਺൪߸͕҆ఆ൛

    View Slide

  18. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2007೥12݄ 1.9.0 (։ൃ൛)
    Matz's Ruby
    Ko1's Ruby

    View Slide

  19. ͜ͷࠒͷόʔδϣχϯάϧʔϧ
    2έλͷ਺ࣈ͸࢖͍ͨ͘ͳ͍
    => 1.10.0 ͸͋Γಘͳ͍
    2.0ͬͯ਺ࣈ͸·ͩ࢖͍ͨ͘ͳ͍
    1.9.0͸։ൃ൛ɺ1.9.1͕҆ఆ൛ͰͲ͏͔

    View Slide

  20. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2007೥12݄ 1.9.0 (։ൃ൛)
    2010೥08݄ 1.9.2 (΄Μͱ͏ͷ҆ఆ൛)

    View Slide

  21. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2007೥12݄ 1.9.0 (։ൃ൛)
    2010೥08݄ 1.9.2 (҆ఆ൛)
    2011೥10݄ 1.9.3 (҆ఆ൛)

    View Slide

  22. Rubyͷόʔδϣϯ൪߸ͷมભ
    1
    1.2
    1.4
    1.6
    1.8
    2
    1995/12 1996/12 1997/08 1998/12 1999/08 2000/09 2003/08 2007/12 2010/08 2011/10

    View Slide

  23. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2007೥12݄ 1.9.0 (։ൃ൛)
    2010೥08݄ 1.9.2 (҆ఆ൛)
    2011೥10݄ 1.9.3 (҆ఆ൛)
    2013೥02݄ 2.0

    View Slide

  24. 2003೥ͷ·ͭ΋ͱ͞ΜͷεϥΠυ
    http://www.rubyist.net/~matz/slides/rc2003/mgp00009.html

    View Slide

  25. 2003೥ͷ·ͭ΋ͱ͞ΜͷεϥΠυ
    http://www.rubyist.net/~matz/slides/rc2003/mgp00009.html
    ࠓճͷ2.0Ͱ࣮૷

    View Slide

  26. Rubyͷྺ࢙
    1993೥02݄ ஀ੜ
    1995೥12݄ ެ։ (0.95)
    1996೥12݄ 1.0
    1997೥08݄ 1.1
    1998೥12݄ 1.2
    1999೥08݄ 1.4
    2000೥09݄ 1.6
    2003೥08݄ 1.8
    2007೥12݄ 1.9.0 (։ൃ൛)
    2010೥08݄ 1.9.2 (҆ఆ൛)
    2013೥02݄ 2.0

    View Slide

  27. 2.0ͷϦϦʔε
    2013೥2݄24೔
    ʮ஀ੜʯ͔Βͪΐ͏Ͳ20प೥
    લ೔ͱ͔ʹ
    2.0ϦϦʔεه೦ & ஀ੜ20प೥Πϕϯτ
    Έ͍ͨͳͷ͕͋ΔΜ͡Όͳ͍͔ͳ͊

    View Slide

  28. 1.9.3..2.0.0
    1.8..1.9΄Ͳͷbig jumpͰ͸ͳ͍
    ຊ౰ʹॏ͍ͨมߋ(= Ѩඓڣש)͸
    1.9Ͱࡁ·ͤͨ
    YARVɹ
    Encodingɹ
    1.9͸2.0 preͩͬͨɺͱ΋ݴ͑Δ͔΋

    View Slide

  29. 2.0ͷಛ௃
    ࠷ॳ͔Β҆ఆ൛Λࢤ޲
    2.0.0͕ग़ͨॠ͔ؒΒ
    ҆৺͓ͯ͠࢖͍͍͚ͨͩ·͢
    1.9.3ͱͷޓ׵ੑΛॏࢹ
    1.9.3͔ΒεϜʔζʹҠߦͰ͖·͢
    ඇޓ׵ͳมߋ͸2.1Ҏ߱ʹ

    View Slide

  30. 1.9.3..2.0.0
    ৽ػೳ
    ύϑΥʔϚϯεͷ޲্
    VM
    GC
    require
    σϑΥϧτεΫϦϓτΤϯίʔσΟϯά
    ͍ͭʹσϑΥϧτUTF-8ʹʂ
    ΋͔ͨ͠͠Β࠷େͷඇޓ׵ (ʁ)

    View Slide

  31. ύϑΥʔϚϯεͷ޲্
    VM
    GC
    require

    View Slide

  32. VM: @ko1

    View Slide

  33. View Slide

  34. GC: @nari3

    View Slide

  35. View Slide

  36. ύϑΥʔϚϯεͷ޲্
    (DEMO) Railsͷىಈ࣌ؒ
    RubyͷόʔδϣϯΛ্͛Δ͚ͩͰഒ଎ʹʂ

    View Slide

  37. σϑΥϧτεΫϦϓτΤϯίʔσΟϯά
    ͍ͭʹσϑΥϧτUTF-8ʹʂ
    (Ϛδίϝͱ͸Կͩͬͨͷ͔…)
    ΋͔ͨ͠͠Β࠷େͷඇޓ׵ (ʁ)

    View Slide

  38. Ϛδίϝͱ͸Կͩͬͨͷ͔
    ๻ΒϢʔβʔʹͱͬͯඞཁͳஈ֊ͩͬͨ
    String͕encodingΛ࣋ͭͱ͍͏֓೦
    CSIɹ
    internal encoding, external encodingɹ
    US-ASCII, ASCII-8BIT, BINARYɹ
    mojibake == ࢮ

    View Slide

  39. ਆల։
    encodingɺͳΜͱͳ͘Θ͔ͬͨͰ͠ΐʁ
    => σϑΥϧτUTF-8
    ੒੉͞Μ͍͢͝

    View Slide

  40. @nalsh

    View Slide

  41. View Slide

  42. M17Nʹ͍ͭͯৄ͘͠
    ʰA Reintroduction To Ruby M17Nʱ
    http://www.slideshare.net/nalsh/a-reintroduction-
    to-ruby-m17-n
    ʰ Ruby M17N ͷઃܭͱ࣮૷ʱ
    http://jp.rubyist.net/magazine/?0025-
    Ruby19_m17n

    View Slide

  43. Ruby 2.0ͷ৽ػೳ
    Refinements
    Module#prepend
    Enumerable#lazy
    ΩʔϫʔυҾ਺
    ͳͲͳͲ

    View Slide

  44. Ruby 2.0ͷ৽ػೳ
    ͋ͱͰ

    View Slide

  45. Rails 4.0

    View Slide

  46. Railsͷόʔδϣϯ൪߸ͷભҠ
    2004೥07݄ ެ։
    2005೥12݄ 1.0
    2007೥12݄ 2.0
    2010೥08݄ 3.0
    2012-2013 4.0

    View Slide

  47. ϝδϟʔόʔδϣϯΞοϓʹ൐͏
    ৽ύϥμΠϜ
    1.0 DRY, CoC
    2.0 RESTful
    3.0 Modularity

    View Slide

  48. ϝδϟʔόʔδϣϯΞοϓʹ൐͏
    ৽ύϥμΠϜ
    1.0 DRY, CoC
    2.0 RESTful
    3.0 Modularity
    4.0 ಛʹͳ͠ʂ

    View Slide

  49. Rails 4
    ʮ৽ػೳʯ͸͍Ζ͍Ζ
    ʮ৽ύϥμΠϜʯ͸ಛʹͳ͍
    جຊతʹ͸3.2ͷਖ਼ৗਐԽܥ
    4.0ʹ͖͔͚ͨͬ͠͸ɺRuby 1.8αϙʔτͷ
    ऴྃ(ʁ)

    View Slide

  50. Railsͷόʔδϣϯ൪߸ઓུ
    όʔδϣϯ൪߸ͳΜͯ০Γ
    Rails͸ઈ͑ؒͳ͘มԽ͢Δ1ຊͷઢ࿏Ͱɺ
    όʔδϣϯͷ۠੾Γ͸్தӺͷΑ͏ͳ΋ͷ

    View Slide

  51. Railsͷʮ৽ʯόʔδϣϯ൪߸ઓུ
    ৽͍͠όʔδϣϯͰ࢖͑ͳ͘ͳΔػೳ͸
    ͍͖ͳΓফ͞ͳ͍
    1ݸલͷόʔδϣϯͰ deprecation warningΛ
    ग़͢
    ࣍ͷόʔδϣϯͰফ͢

    View Slide

  52. 4.0ͷಛ௃
    ࠷ॳ͔Β҆ఆ൛Λࢤ޲
    4.0.0͕ग़ͨॠ͔ؒΒ
    ҆৺͓ͯ͠࢖͍͍͚ͨͩ·͢
    3.2.xͱͷޓ׵ੑΛॏࢹ
    3.2.x͔ΒεϜʔζʹҠߦͰ͖·͢

    View Slide

  53. Railsͷόʔδϣϯ൪߸ઓུ
    όʔδϣϯ൪߸ͳΜͯ০Γ
    Rails͸ઈ͑ؒͳ͘มԽ͢Δ1ຊͷઢ࿏Ͱɺ
    όʔδϣϯͷ۠੾Γ͸్தӺͷΑ͏ͳ΋ͷ
    ͳͷͰɺ4.0ͷ৽ػೳ͕Ͳ͏͜͏ݴ͏ΑΓ΋
    ·ͣɺେ͖ͳྲྀΕΛ೺Ѳ͢Δͱྑ͍͔΋

    View Slide

  54. ࠷ۙͷைྲྀ
    Modern
    Speed
    Security
    Real-time web
    ActiveRecord
    Social coding

    View Slide

  55. Modern
    Ruby '>= 1.9.3'ɹ
    APIͷ͞ΒͳΔચ࿅
    ݹ͍ػೳɺ͋Μ·Γ࢖ΘΕͯͳ͍ػೳΛ
    ΋Γ΋Γ֎෦Gem΁

    View Slide

  56. ৽API
    AR͍Ζ͍Ζ
    AR.where!
    AR.all (= .scoped)
    scope :foo, -> {}
    NullRelation
    AR::Model, AMo::Model
    update_columns
    AR.where.not
    PATCH verb
    routing concern
    Russian doll caching

    View Slide

  57. RIP
    Ruby 1.8 support
    vendor/plugins
    ActiveResource
    AR.find :all
    dynamic finders
    ActiveRecord::SessionStore
    Rack::Cache

    View Slide

  58. Speed
    ύϑΥʔϚϯε޲্
    Ruby 1.9Ҡߦʹ൐͏ίʔυͷεϦϜԽ
    Sprocketsͷprecompile
    threadsafe!
    AS::Queue
    TurboLinks

    View Slide

  59. Security
    ʮMass Assignment Securityʯ
    =>ʮStrong Parametersʯ

    View Slide

  60. Real-time web
    AC::Live (@tenderlove)

    View Slide

  61. @tenderlove

    View Slide

  62. AC::Live
    "Real Time Salami" https://speakerdeck.com/
    tenderlove/real-time-salami

    View Slide

  63. ActiveRecord
    @tenderlove
    @jonleighton
    PostgreSQL

    View Slide

  64. @jonleighton

    View Slide

  65. Social coding
    2721 peopleʂ
    http://contributors.rubyonrails.org/ɹ
    ೆถ
    @josevalim
    @spastorino
    ൴Βʹଓ͘ୈ3ੈ୅

    View Slide

  66. @josevalim

    View Slide

  67. @spastorino

    View Slide

  68. ͓͠Βͤ
    @josevailm is
    speaking at
    RubyKaigi 2013ʂ

    View Slide

  69. Ruby 2.0ͷ࿩͸ʁ

    View Slide

  70. RubyConfͰ͠Ό΂ͬͨ΍ͭ
    Ruby 2.0 on Rails
    http://speakerdeck.com/u/a_matsuda/p/ruby-2-
    dot-0-on-rails
    Ruby 2.0 on Rails (video)
    http://www.confreaks.com/videos/1275-
    rubyconf2012-ruby-2-0-on-rails

    View Slide

  71. ensure
    The new Ruby world is coming!ɹ
    People are making the Ruby world better
    everyday!
    Meet the people (= the community) and say
    "Hi!" to them! <3 <3 <3

    View Slide

  72. ensure
    Welcome to the new Ruby world!ɹ
    Meet the people at:
    Asakusa.rbɹ
    Railsษڧձ
    େߐށRubyձٞ03
    RubyKaigi 2013

    View Slide

  73. end

    View Slide