“kenkenize”で触れるRubyの中身 / Kenkenization and the Ruby Internal

23f4d5d797a91b6d17d627b90b5a42d9?s=47 Kentaro Kuribayashi
October 31, 2019
170

“kenkenize”で触れるRubyの中身 / Kenkenization and the Ruby Internal

23f4d5d797a91b6d17d627b90b5a42d9?s=128

Kentaro Kuribayashi

October 31, 2019
Tweet

Transcript

  1. ʙϝλϓϩάϥϛϯάೖ໳ͱͯ͠ʙ ܀ྛ݈ଠ࿠(.01FQBCP *OD ,3VCZ lLFOLFOJ[FzͰ৮ΕΔ3VCZͷத਎

  2. (.0ϖύϘגࣜձࣾ ܀ྛ݈ଠ࿠BLB͋ΜͪΆͪΌΜ औక໾$50ɺࣛࣇౡΦϑΟενʔϜ੹೚ऀ IUUQTLFOUBSPLPSH

  3. ໨࣍ ࣄͷൃ୺ LFOLFOHFNͷઆ໌ LFOLFOHFNͷ࣮૷ ͓ΘΓʹ

  4. ࣄͷൃ୺

  5. LFOLFOʹಥવ;ͬͯΘ͍ͨةػ ࣛࣇౡΦϑΟενʔϜʹLFOLFOͱ͍͏໊͋ͩͷΤϯδχΞ͕͍Δͷ͕ͩɺ ಥવͷվ໊ఏҊʹΑΔ໊͋ͩͷةػʂʂ̍

  6. LFOLFOΛकΕʂʢʣ ·͋ɺͦ͏ͳΓ·͢ΑͶʜʜɻ

  7. LFOLFOΛकΕʂʢʣ স͍ͷઈ͑ͳ͍ΞοτϗʔϜͳ৬৔Ͱ͢ɻ

  8. LFOLFOΛकΕʂʢʣ ᰜ૘ͱݱΕΔΘͨ͘͠ͷఏҊɻ

  9. lLFOLFOJ[Fzͷཁ݅ wཁ݅ ken ^ 2͕จࣈྻkenkenΛฦ͢ wͨͩ͠ɺม਺ ken ʹจࣈྻken ͕ೖͬͯͯɺͦΕ͕ϝιου ^

    ʹΑΓO ճ܁Γฦ͞ΕΔͱ͍͏࣮૷ͩͱͭ·Βͳ͍Ͱ͢ΑͶ wͦ͜Ͱɺม਺ʹ͍͔ͳΔจࣈྻ͕ೖ͍ͬͯͯ΋ɺม਺໊Λnճ܁Γฦ͢͜ͱͰ ཁ݅Λຬͨ͢ίʔυʹ͍ͨ͠ɻ͜ͷॲཧΛlLFOLFOJ[FzͱݺͿɻ ͋ͳͨͳΒͲ͏͠·͔͢ʁߟ͑ͯΈ͍ͯͩ͘͞ɻ
  10. LFOLFOHFNͷઆ໌

  11. IUUQTHJUIVCDPNLFOUBSPLFOLFO

  12. LFOLFOHFNͷ࢖͍ํʢʣ

  13. LFOLFOHFNͷ࢖͍ํʢʣ จࣈྻ͕ͳΜͰ͋Δ͔ʹؔΘΒͣɺ ม਺໊͔Β܁Γฦ͢จࣈ͕ܾఆ͞ΕΔ

  14. ཁ݅ͷ֬ೝ 㾎ཁ݅ ken ^ 2͕จࣈྻkenkenΛฦ͢ 㾎ͨͩ͠ɺม਺ ken ʹจࣈྻken ͕ೖͬͯͯɺͦΕ͕ϝιου ^

    ʹΑΓO ճ܁Γฦ͞ΕΔͱ͍͏࣮૷ͩͱͭ·Βͳ͍Ͱ͢ΑͶ 㾎ͦ͜Ͱɺม਺ʹ͍͔ͳΔจࣈྻ͕ೖ͍ͬͯͯ΋ɺม਺໊Λnճ܁Γฦ͢͜ͱ Ͱཁ݅Λຬͨ͢ίʔυʹ͍ͨ͠ɻ͜ͷॲཧΛlLFOLFOJ[FzͱݺͿɻ ཁ݅ΛຬͨͤͨʂLFOLFOͷ໊͕͋ͩकΒΕͨʂʂ̍
  15. LFOLFOHFNͷ࣮૷

  16. LFOLFOHFN࣮૷ͷίΞʢൈਮʣ

  17. eval͢Δ࣌ʹ3VCZͷ಺෦Ͱى͍ͬͯ͜Δ͜ͱʜᶃ 1BU4IBVHIOFTTZ 3VCZ6OEFSB.JDSPTDPQF"O*MMVTUSBUFE(VJEFUP3VCZ*OUFSOBMT /P4UBSDI1SFTT  QQ

  18. eval͢Δ࣌ʹ3VCZͷ಺෦Ͱى͍ͬͯ͜Δ͜ͱʜᶄ 1BU4IBVHIOFTTZ 3VCZ6OEFSB.JDSPTDPQF"O*MMVTUSBUFE(VJEFUP3VCZ*OUFSOBMT /P4UBSDI1SFTT  QQ

  19. LFOLFOHFN࣮૷΁ͷಓے wᶃͷྫ͔Β weval ͢Δͱɺ৽͍͠ελοΫϑϨʔϜ͕࡞੒͞ΕΔ wͦͷελοΫϑϨʔϜ͔Β͸ɺEPΛ௨ͯ͡ݩͷจ຺ͷม਺ΛࢀরͰ͖Δ wᶄͷྫ͔Β wbindingΛ௨ͯ͡ɺݺͼग़͞Εͨϝιου಺ͷม਺ΛࢀরͰ͖Δ wͭ·ΓɺbindingΛऔಘ͑͞Ͱ͖Ε͹ɺͦͷٯ΋Ͱ͖Δʹҧ͍ͳ͍ wϝιουݺͼग़͠ݩͷbindingΛ௨ͯࣗ͡෼ͷม਺໊ΛऔಘͰ͖Δ͸ͣʂ

  20. LFOLFOHFN࣮૷ͷίΞͷղઆ ᶃݱࡏͷϑϨʔϜͷ;ͨͭ ্ͷbindingΛऔಘ ᶄᶃͷϑϨʔϜ্ͷϩʔΧ ϧม਺ҰཡΛऔಘ ᶅᶄͰऔಘͨ͠ม਺໊Λᶃ ্ͰධՁ͠ɺ஋ΛಘΔ ᶆᶅͰಘͨ஋ͱࣗ෼ࣗ਎ selfΛൺֱɻಉ͡ͳΒɺ ͦΕ͕໨తͷม਺Ͱ͋Δɻ

    binding#of_callerϝιου͸ɺCJOEJOH@PG@DBMMFSHFNʹΑͬͯ௥Ճ͞ΕͨϝιουͰɺίʔϧελοΫΛ͔͞ͷ΅ͬͯCJOEJOHΛऔಘͰ͖Δɻ
  21. ͓ΘΓʹ

  22. ·ͱΊͱิ଍ wٕज़͕ͻͱΓͷਓؒͷ໊͋ͩΛकͬͨʂਖ਼͕࣮ٛߦ͞Εͨʂʂ̍ wݴޠͷ಺෦࣮૷ʹؔ͢ΔΠϝʔδ͕͋Δͱɺൃ૝ͷ෯͕޿͕Δʢ͔΋ʣ weval+binding΍ɺ͜͜Ͱ͸ղઆ͠ͳ͔ͬͨModule#class_eval  BasicObject#instance_eval౳Λ࢖͏ͱɺݱࡏͷίϯςΩετΛ͋Ε͜ ΕมߋͰ͖Δ w3VCZͰϝλϓϩάϥϛϯάΛ͍ͯ͠Δ৔߹ɺͦ͏͍͏ख๏Λ༻͍͍ͯΔ͜ͱ ͕ଟ͍ͷͰɺ஌͓ͬͯ͘ͱίʔυϦʔσΟϯάͷ໾ʹཱͭ ˞ࢀরͨ͠ॻ੶͸೥ץߦͷͨΊɺ࠷৽ͷ3VCZʹ͓͍ͯ͸಺෦࣮૷͕ҧ͍ͬͯΔ͔΋͠Ε·ͤΜɻͦͷลͷ֬ೝ͸ɺࠓޙͷ՝୊ͱ͍͏͜ͱͰɻ