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

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ͷ্ڃςΫχοΫ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  4. 3VCZͱ͍͑͹ɺ%4-

    View full-size slide

  5. 3BLF 34QFD 4JOBUSB FUD

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. ಈ͖ͷ֓ཁ
    Ϣʔβʔ໨ઢ
    w Ϟδϡʔϧʢ͜͜Ͱ͸A"MCB3FTPVSDFAʣΛJODMVEF͢ΔͱΫϥε
    ϝιουʢΫϥεϚΫϩʣ͕௥Ճ͞ΕΔ
    w ௥Ճ͞ΕͨΫϥεϝιουʢ͜͜Ͱ͸ABUUSJCVUFTAͳͲʣΛݺͿ͜
    ͱͰΫϥε಺෦ʹ৘ใ͕஝ੵ͞ΕΔ
    w Πϯελϯεϝιουʢ͜͜Ͱ͸ATFSJBMJ[FAʣΛݺͿ͜ͱͰɺ஝ੵ
    ͞Εͨ৘ใͱҾ਺ͷΦϒδΣΫτʢ͜͜Ͱ͸AVTFSAʣ͔ΒಘΒΕ
    ͨ৘ใͱ߹Θͤͯ໨తͷ+40/Λऔಘ͢Δ

    View full-size slide

  10. ಺෦ͷಈ࡞
    ࣮ࡍͷίʔυ͸ޙͰڞ༗͢ΔࢀߟࢿྉΛݟͯͶ
    w Ϟδϡʔϧ͸AJODMVEFEAϑοΫΛఆٛ͠ɺͦͷதͰΠϯελϯεϝιο
    υͱΫϥεϝιουΛಉ࣌ʹ௥Ճ͠͞ΒʹԼهͷΫϥεΠϯελϯεม
    ਺ͷॳظ஋Λઃఆ͢Δ
    w ௥Ճ͞ΕͨΫϥεϝιουΛݺͿͱΫϥεΠϯελϯεม਺ʢ3VCZͰ͸
    Ϋϥε͸ΦϒδΣΫτͳͷͰΠϯελϯεม਺Λ࣋ͯΔʣ͕ઃఆ͞ΕΔ
    w ΫϥεͷAJOJUJBMJ[FAϝιου಺Ͱࣗ਎ͷΫϥεʹઃఆ͞Ε͍ͯΔΫϥε
    Πϯελϯεม਺ΛऔΓग़͠ɺΠϯελϯεͷΠϯελϯεม਺ʹઃఆ
    ͢Δ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  17. ࢀߟࢿྉ
    w IUUQTHJUIVCDPNPLVSBNBTBGVNJBMCB

    View full-size slide