$30 off During Our Annual Pro Sale. View Details »

A technique to implement DSL in Ruby

A technique to implement DSL in Ruby

Masafumi Okura

May 14, 2022
Tweet

More Decks by Masafumi Okura

Other Decks in Programming

Transcript

  1. 0,63".BTBGVNJ  %4-Λ࡞Δͱ͖ʹศརͳςΫχ οΫ!3VCZ 3VCZͷ্ڃςΫχοΫ 

  2. ஫ҙɿૣޱͰ͢ɻ εϥΠυ͸ޙͰ্͛·͢ɻ ͝ҙݟ͝ײ૝͸νϟοτ͔5XJUUFSͰɻ 

  3. ࣗݾ঺հ !PLVSBNBTBGVNJ w ໊લɿେ૔խ࢙ w ॴଐɿϑϦʔϥϯε w ׆ಈɿ,BJHJPO3BJMTͱ͍͏ΧϯϑΝϨϯεͷνʔϑΦʔΨφΠβʔͳͲ w 044ɿ"MCBʢ+40/γϦΞϥΠβ࣮૷ʣͳͲ

    w ৄࡉ͸IUUQTUFDIGFFEJPQFPQMF!PLVSBNBTBGVNJ 
  4. 3VCZͱ͍͑͹ɺ%4- 

  5. 3BLF 34QFD 4JOBUSB FUD 

  6. %4-Λศརʹॻ͘ํ๏Λ͝঺հ 

  7. ࠓճऔΓ্͛Δͷ͸ͪ͜Β 

  8. 

  9. 

  10. ࣗ࡞ͷΫϥε಺ʹϚΫϩͬΆ͘ॻ ͍͍ͯ͘λΠϓʢΫϥεϚΫϩʣ 

  11. ࢖͍ํ 

  12. 

  13. ಈ͖ͷ֓ཁ Ϣʔβʔ໨ઢ w Ϟδϡʔϧʢ͜͜Ͱ͸A"MCB3FTPVSDFAʣΛJODMVEF͢ΔͱΫϥε ϝιουʢΫϥεϚΫϩʣ͕௥Ճ͞ΕΔ w ௥Ճ͞ΕͨΫϥεϝιουʢ͜͜Ͱ͸ABUUSJCVUFTAͳͲʣΛݺͿ͜ ͱͰΫϥε಺෦ʹ৘ใ͕஝ੵ͞ΕΔ w Πϯελϯεϝιουʢ͜͜Ͱ͸ATFSJBMJ[FAʣΛݺͿ͜ͱͰɺ஝ੵ

    ͞Εͨ৘ใͱҾ਺ͷΦϒδΣΫτʢ͜͜Ͱ͸AVTFSAʣ͔ΒಘΒΕ ͨ৘ใͱ߹Θͤͯ໨తͷ+40/Λऔಘ͢Δ 
  14. ಺෦ͷಈ࡞ ࣮ࡍͷίʔυ͸ޙͰڞ༗͢ΔࢀߟࢿྉΛݟͯͶ w Ϟδϡʔϧ͸AJODMVEFEAϑοΫΛఆٛ͠ɺͦͷதͰΠϯελϯεϝιο υͱΫϥεϝιουΛಉ࣌ʹ௥Ճ͠͞ΒʹԼهͷΫϥεΠϯελϯεม ਺ͷॳظ஋Λઃఆ͢Δ w ௥Ճ͞ΕͨΫϥεϝιουΛݺͿͱΫϥεΠϯελϯεม਺ʢ3VCZͰ͸ Ϋϥε͸ΦϒδΣΫτͳͷͰΠϯελϯεม਺Λ࣋ͯΔʣ͕ઃఆ͞ΕΔ w

    ΫϥεͷAJOJUJBMJ[FAϝιου಺Ͱࣗ਎ͷΫϥεʹઃఆ͞Ε͍ͯΔΫϥε Πϯελϯεม਺ΛऔΓग़͠ɺΠϯελϯεͷΠϯελϯεม਺ʹઃఆ ͢Δ 
  15. ՝୊ 

  16. ઃఆ͢Δ΂͖ΫϥεΠϯελϯε ม਺ͷ߲໨ͱॳظ஋͕ࢄΒ͹Δ 

  17. ΫϥεͷܧঝΛߟ͑Δͱ͞Βʹ΍ ΍͍͜͠ 

  18. ΫϥεΠϯελϯεม਺͕ؔΘΔՕॴ w "MCB3FTPVSDF͕JODMVEF͞Εͨͱ͖ʹݩΫϥεʹΫϥεΠϯελ ϯεม਺Λॳظ஋ͱͱ΋ʹઃఆ w "MCB3FTPVSDFΛJODMVEFͨ͠Ϋϥε͕ΠϯελϯεԽ͞Εͨͱ͖ ʹΫϥεͷΫϥεΠϯελϯεม਺ΛΠϯελϯεͷΠϯελϯε ม਺ʹઃఆ w "MCB3FTPVSDFΛJODMVEFͨ͠ΫϥεΛܧঝͨ͠ͱ͖ɺ਌Ϋϥεͷ

    ΫϥεΠϯελϯεม਺ΛࢠΫϥεʹίϐʔ 
  19. ղܾࡦ 

  20. 

  21. 

  22. 

  23. ࠓ೔ͷςΫχοΫ ఆ਺Λ࢖͓͏ฤ w ࢄΒ͹ͬͨ৘ใΛू໿͢Δͷʹఆ਺Λ࢖͏ w 3VCZͷఆ਺͸޿ൣғ͔ΒࢀরՄೳͰɺωετͨ͠ϋογϡͷΑ͏ͳ ෳࡶͳߏ଄Λอ࣋Ͱ͖ΔͷͰศར w ఆ਺ʹ֨ೲ͞Εͨॳظ஋Λઃఆ͍ͨ͠৔߹ɺADMPOFA·ͨ͸AEVQAΛ ࢖Θͳ͍ͱෳ਺ͷΦϒδΣΫτ͕ಉҰͷϝϞϦྖҬΛࢀরͨ͠Γมߋ

    ͨ͠Γͯ͠όάʹͳΔͷͰؾΛ͚ͭΑ͏ w 
  24. ࠓ೔ͷςΫχοΫʢʣ ϝλϓϩάϥϛϯάฤ w େྔͷΠϯελϯεม਺Λઃఆ͍ͨ͠ͱ͖͸ϧʔϓͷதͰ AJOTUBODF@WBSJBCMF@TFUA͢Δͱศར w AJODMVEFEAͱAJOIFSJUFEAϑοΫΛ૊Έ߹ΘͤΔ͜ͱͰ࢖͍উखͷ ྑ͍%4-ΛఏڙͰ͖Δ 

  25. 3VCZͰָ͍͠%4-ϥΠϑΛʂ 

  26. ࢀߟࢿྉ w IUUQTHJUIVCDPNPLVSBNBTBGVNJBMCB