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

try_to_making_a_gem_with_pattern_matching.pdf

1fabfca5092bfe3f0712a0e66392f165?s=47 morihirok
October 16, 2019

 try_to_making_a_gem_with_pattern_matching.pdf

Ebisu.rb #25

1fabfca5092bfe3f0712a0e66392f165?s=128

morihirok

October 16, 2019
Tweet

Transcript

  1. Ruby2.7Ͱಋೖ͞ΕΔ Pattern matchingͰ GemΛ࡞ͬͯΈͨ Ebisu.rb #25 @_morihirok

  2. About me • Github: morihirok • Twitter: @_morihirok • STORES.jp

    inc,
  3. Ruby 2.7ΑΓ Pattern matching ͱ͍͏ػೳ͕ೖΓ·͢

  4. 3VCZ,BJHJ1BUUFSONBUDIJOH/FXGFBUVSFJO3VCZΑΓҾ༻ IUUQTTQFBLFSEFDLDPNL@UTKQBUUFSONBUDIJOHOFXGFBUVSFJOSVCZEPU

  5. 3VCZ,BJHJ1BUUFSONBUDIJOH/FXGFBUVSFJO3VCZΑΓҾ༻ IUUQTTQFBLFSEFDLDPNL@UTKQBUUFSONBUDIJOHOFXGFBUVSFJOSVCZEPU

  6. ࢖ͬͯΈ͍ͨͷͰ Կ͔࡞Ζ͏

  7. STORES.jp͸ϝΠϯDB͕ MongoDB • ओཁͳσʔλ͸શͯMongoDBʹೖ͍ͬͯΔ • ओཁͳΫΤϦ΋શͯMongoDBʹ޲͔͍ͬͯΔ • ౰વ࣮ߦܭը΋MongoDBͷ΋ͷΛ֬ೝ͢Δ • MongoDBͷexplain͸ಡΈͮΒ͍

  8. MongoDBͷexplain݁Ռͷ αϯϓϧ > db.items.find({price: 119}).explain("executionStats") { "queryPlanner" : { "plannerVersion"

    : 1, "namespace" : "sample_db.items", "indexFilterSet" : false, "parsedQuery" : { "price" : { "$eq" : 119 } }, "winningPlan" : { "stage" : "COLLSCAN", "filter" : { "price" : { "$eq" : 119 } શͯ+40/Ͱදݱ͞ΕΔ
  9. Pattern matchingΛ࢖͑͹ JSONͷѻ͍͕ ָʹͳΔͷͰ͸ʁ

  10. ͱ͍͏͜ͱͰ࡞ͬͨͷ͕͜Ε FYQMBJOͷ+40/Λ ͍͍۩߹ʹ.BSLEPXOͷ ςʔϒϧʹม׵͢Δ

  11. ΠϯσοΫε͕ޮ͍ͯͳ͍ͱ͖ͷ explain݁Ռ ͕͜͜z$0--4$"/zʹͳΔ

  12. ͜͏ॻ͚Δ ͕͜͜z$0--4$"/zʹͳΔ

  13. ΠϯσοΫε͕ޮ͍͍ͯΔͱ͖ͷ explain݁Ռ ͕͜͜z'&5$)zʹมΘΔ ͕͜͜z*94$"/zʹͳΔ ͜͜ʹΠϯσοΫε໊͕ೖΔ

  14. ͜͏ॻ͚Δ ͕͜͜z'&5$)zʹมΘΔ ͕͜͜z*94$"/zʹͳΔ ͜͜ʹΠϯσοΫε໊͕ೖΔ

  15. ͜͏ॻ͚Δ ม਺ΛόΠϯυͰ͖Δ ͜͜ʹΠϯσοΫε໊͕ೖΔ

  16. ࠷ऴతʹ͸͜͏ͳΔ

  17. STORES.jpͰ΋ ͍͍ײ͡ʹ࢖͑ͦ͏

  18. ͓લ͸ຊ൪ͷRubyΛ 2.7ʹ্͛Δͭ΋Γͳͷ͔ʁ

  19. Pattern matchingແ͠Ͱ ॻ͖׵͑Δͱ

  20. Pattern matchingແ͠Ͱ ॻ͖׵͑Δͱ όʔδϣϯ͝ͱͷ ίʔυͷဃ཭͕ܹ͘͠ͳΔ

  21. ͜Μͳํ๏΋͋Γ·͢

  22. pattern-matchΛར༻͢Δͱ 1SPDDBMM ͷγϯλοΫεγϡΨʔ͕  Ͱ͋Δ͜ͱΛར༻͍ͯ͠Δ

  23. pattern-matchΛར༻͢Δͱ ͋Δఔ౓ࣅͨίʔυΛ อͭ͜ͱ͕Ͱ͖Δ

  24. Ruby2.7Ҏ্Ͱ͸ Pattern matchingΛ࢖͍͍ͨ Ruby2.6ҎԼͰ΋ gem͸࢖͍͍ͨ

  25. RubyͷόʔδϣϯʹΑͬͯ require͢ΔϑΝΠϧΛม͑Δ • mongo_clarify.rb 3VCZͷόʔδϣϯʹΑͬͯ ϑΝΠϧΛม͍͑ͨϞδϡʔϧ

  26. RubyͷόʔδϣϯʹΑͬͯ require͢ΔϑΝΠϧΛม͑Δ • investigate.rb 3VCZҎ্ͳΒ 1BUUFSO.BUDIJOH൛Λ࢖͏

  27. • ىಈதͷRubyͷόʔδϣϯจࣈྻΛอ࣋͢Δ ఆ਺ Gem::Version • όʔδϣϯจࣈྻΛൺֱՄೳʹ͢ΔΫϥε RUBY_VERSION

  28. ςετ΋RubyͷόʔδϣϯʹΑͬͯ require͢ΔϑΝΠϧΛม͑Δ • mongo_clarify_spec.rb 3VCZͷόʔδϣϯʹΑͬͯ ϑΝΠϧΛม͍͑ͨϞδϡʔϧ

  29. ςετ΋RubyͷόʔδϣϯʹΑͬͯ require͢ΔϑΝΠϧΛม͑Δ • .travis.yml $*ʹෳ਺όʔδϣϯͰ ςετͯ͠΋Β͏

  30. RubyGemsʹస͕͍ͬͯ·͢ • https://rubygems.org/gems/mongo_clarify

  31. ༨ஊ Gemͷ࡞੒աఔͰ MongoDBͷexplainʹ׳Ε ͜ͷGem࢖͍ͬͯͳ͍