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

Rubyを説明するのは難しい(仮) / ruby is difficult

Rubyを説明するのは難しい(仮) / ruby is difficult

http://regional.rubykaigi.org/tochigi08/

とちぎRuby会議08での資料です

sugamasao

June 29, 2019
Tweet

More Decks by sugamasao

Other Decks in Technology

Transcript

  1. RubyΛઆ໌͢Δͷ͸
    ೉͍͠ʢԾʣ
    ͱͪ͗Rubyձٞ08(2019/6/29)
    [email protected]

    View full-size slide

  2. RubyΛઆ໌͢Δͷ͸
    ೉͍͠
    ͱͪ͗Rubyձٞ08(2019/6/29)
    [email protected]
    ʢϓϩάϥϜΛڭ͑Δ࣌ʹʣ

    View full-size slide

  3. ͱ͜ΖͰͩΕʁ
    • HN sugamasao
    • PN ͕͢ΘΒ·͞ͷΓ
    • Rubyྺ 13೥͘Β͍(…!!)
    • Rails͸ͦΜͳʹಘҙͰ͸ͳ͍
    • Rubyʹؔ͢ΔΛ͍͔ͭ͘✍͠·ͨ͠

    View full-size slide

  4. ࣥචྺ
    2013 ύʔϑΣΫτRuby(ڞஶ)
    2014 WebΞϓϦΤϯδχΞཆ੒ಡຊ(ڞஶ)
    2014 ύʔϑΣΫτRuby on Rails(ڞஶ)
    2017 վఆ2൛ ύʔϑΣΫτRuby(ڞஶ)
    2018 ͔ΜͨΜRuby(୯ஶ)
    2019 ???

    View full-size slide

  5. ͔ΜͨΜRubyࣥචͷࡍʹ೉͠
    ͍ͳʙͱࢥͬͨ෦෼ͱɺ࠷ऴత
    ʹͲ͏͍͏આ໌ʹͳ͔ͬͨΛղ
    આͯ͠ɺօ͞Μͷࠓޙͷࢀߟʹ
    ͳΔͱྑ͍ͳͱࢥ͍·͢
    ͜͏͍͏આ໌Ͱ͏·͍ͬͨ͘Αʂͱ͍͏͓
    ࿩Λ͓࣋ͪͷํ͸৭ʑڭ͍͑ͯͩ͘͞

    View full-size slide

  6. ͔ΜͨΜRuby
    ͱ͸ʁ

    View full-size slide

  7. ͔ΜͨΜRuby
    lຊॻ͸ɼʮ޿͘ɾਖ਼͘͠ɾ৽͘͠ʯΛ
    ίϯηϓτʹ3VCZͰϓϩάϥϛϯάΛ
    ͸͡ΊΔʹ౰ͨͬͯجຊతͳ͜ͱ͸͢΂
    ֶͯशͰ͖Δ಺༰ͱͳ͍ͬͯ·͢ɻ
    ʢҎԼུʣz
    https://gihyo.jp/book/2018/978-4-7741-
    9861-3
    “͔ΜͨΜγϦʔζ”ͷRuby൛

    View full-size slide

  8. ͍ΘΏΔ
    ೖ໳ॻ

    View full-size slide

  9. ࣥචςʔϚ
    • ଞͷݴޠͷ஌͕ࣝͳͯ͘΋Rubyͷجຊ͕Θ͔Δ
    • RubyͷϦϑΝϨϯεϚχϡΞϧΛಡΊΔΑ͏ʹͳΔ
    • ࣮ࡍʹ࢖ΘΕΔίʔυ͕Rubyͷίʔυͱͯ͠ಡΊΔ

    ʢ͋Δ͍͸ௐ΂ΒΕΔʣΑ͏ʹͳΔ

    View full-size slide

  10. ଞͷݴޠͷ஌͕ࣝͳͯ͘΋
    Rubyͷجຊ͕Θ͔Δ

    View full-size slide

  11. ଞͷݴޠͷ஌͕ࣝͳͯ͘΋Rubyͷجຊ͕Θ͔Δ
    ·͋ೖ໳ॻͳͷͰɾɾɾ
    hogeݴޠͷ֓೦͸RubyͰݴ͏ͱ͜͏ͩΑʂ
    Ͱ͸ͳ͘ɺϓϩάϥϛϯάͱͯ͠ͷجຊΛ཈͑
    ΒΕΔΑ͏ʹ
    :
    https://magazine.rubyist.net/articles/0001/0001-Hotlinks.html

    View full-size slide

  12. RubyͷϦϑΝϨϯεϚχϡΞϧ
    ΛಡΊΔΑ͏ʹͳΔ

    View full-size slide

  13. RubyͷϦϑΝϨϯεϚχϡΞϧΛಡΊΔΑ͏ʹͳΔ
    ͜ͷ఺͸ҟৗʹͩ͜Θ͍ͬͯͯɺຊॻͰ
    ղઆ͢Δͱ͖ϦϑΝϨϯεϚχϡΞϧͷ
    ϦϯΫΛ͚͍ͭͯΔ
    ʢϦϑΝϨϯεϚχϡΞϧͷಡΈํ͔Βղઆ͕͋Δκʣ
    ʢ૊ΈࠐΈϥΠϒϥϦͱඪ४ఴ෇ϥΠϒϥϦͱ͔͍ܰॳݟࡴ͠
    ͩ͠……ʣ
    :
    ࡞ͬͯΈ͍ͨ΋ͷ͕ࢥ͍͍ͭͯ΋ௐ΂ํ͕Θ͔Βͳ͍ͱͲ͏ʹ΋ͳΒ
    ͳ͍ͷͰɺ࠷΋ॏཁͳ఺ͩͱߟ͍͑ͯ·͢

    View full-size slide

  14. ࣮ࡍʹ࢖ΘΕΔίʔυ͕ಡΊΔ

    View full-size slide

  15. ࣮ࡍʹ࢖ΘΕΔίʔυ͕ಡΊΔ
    ૉ๿ͳղઆʹऴ࢝ͯ͠͠·͏ͱɺ%ه๏ͷΑ͏ͳ
    આ໌༏ઌ౓ͱͯ͠͸௿͍ʢ͋Ε΋͜Ε΋ͱઆ໌͢Δͱ࿩͕ൃࢄ͠
    ͪΌ͏ͷͰʣ͚Ͳ࣮ίʔυͰ͸;ͭ͏ʹग़ͯ͘ΔɺΈͨ
    ͍ͳ΋ͷ͸Ͳ͏ʹ͔ͯ͠ղઆ͍ͯ͋͛ͨ͠
    ຊΛಡΜͰ͍Δ࣌఺Ͱ͖ͪΜͱཧղͰ͖ͳͯ͘΋
    ʮ஌ͬͯʯ͍Ε͹ʮௐ΂ʯΒΕΔ͸ͣͳͷͰ

    View full-size slide

  16. ೖ໳ॻͱݴͬͯ΋
    ର৅ಡऀϨϕϧʹΑͬͯ
    ੾Γޱ͸ҟͳΓ·͢

    View full-size slide

  17. https://speakerdeck.com/igaiga/dive-into-code-rails-ruby-books?slide=10
    @igaiga555͞ΜʹΑΔ࠷ۙͷॻ੶ͷ෼ྨ

    View full-size slide

  18. ͔ΜͨΜRuby͸
    ʮଞݴޠܦݧ͋Γʯ
    ͷதͰ͸ϏΪφʔ޲͚

    View full-size slide

  19. ……ͱ͍͏Ϩϕϧײʹ͍ͭͯ
    ղઆΛ࡞͍ͬͯͨͷͰ͕͢ɺ
    ΑΓత֬ͳจষʹग़ձͬͨͷ
    ͰҾ༻͠·͢Ͷ

    View full-size slide

  20. Matz͞ΜʹΑΔΦεεϝ
    https://jp.quora.com/
    Ruby%E8%A8%80%E8%AA%9E%E3%82%92%E5%AD%A6%E3%81%B3%E5%A7%8B%E3%82%81%E3%82%8
    B%E3%81%AE%E6%99%82%E3%81%AB%E4%B8%80%E7%95%AA%E3%82%AA%E3%82%B9%E3%82%B9%
    E3%83%A1%E3%81%AE%E6%9B%B8%E7%B1%8D%E3%81%AF%E3%81%A9%E3%82%8C
    ͍͢͝త֬!!!

    View full-size slide

  21. ʢ౜ಥʣ
    RubyΛଞͷਓʹ
    ڭ͑Δͷͬͯ
    ೉͘͠ͳ͍Ͱ͔͢ʁ

    View full-size slide

  22. ϜζΧγΠφʔͱ
    ࢥͬͨ͜ͱ͕͋Δਓ
    ʢ໰͍͕ࡶ͗͢·͢Ͷʣ

    View full-size slide

  23. ࣍ͷίʔυΛݟͯ
    ࡞ऀͷؾ࣋ͪΛ
    ߟ͑Α
    ※కΊ੾ΓͷϓϨογϟʔ΍ࣥච͕πϥ͍ͳͲ͸ৗ࣌
    ൃಈ͍ͯ͠ΔͷͰɺ͜͜Ͱ͸ߟ͑ͳ͍΋ͷͱ͢Δ

    View full-size slide


  24. Hello, world!ͷαϯϓϧίʔυΛ
    ղઆ͍ͨ͠
    puts "Hello, world!"

    View full-size slide

  25. ࡞ऀͷߟ͑
    hogeݴޠʹൺ΂ͯγϯϓϧʹॻ͚ΔΑʢͱݴ͍
    ͍͕ͨΠϚυΩͦΕΛϝϦοτͱ͢Δ͔ʁʣ
    putsϝιουΛ࢖ͬͯจࣈྻΛग़ྗ͢ΔΑ
    Kernelʹఆ͍ٛͯ͠Δϝιουͩؔ͠਺෩ϝ
    ιουͬͯݴͬͨํ͕ྑ͔ͬͨΓ͢Δͷ͔ͳ
    ͦ΋ͦ΋Ϩγʔόͷͳ͍ϝιουӠʑͷઆ໌Α
    ͍΍͍΍ɺͦ΋ͦ΋putsϝιουͬͯԿͩΑ
    w w w w
    ࠓͷஈ֊Ͱͦ͜·Ͱݴ͏ඞཁͳ͍ɺৄࡉΛઆ໌
    ͤͣʹ఻͑ͳ͍ͱͩ

    View full-size slide

  26. ຊॻͷ౴͑
    ͜͏ͳΔ
    P24

    View full-size slide

  27. ຊॻΛॻ্͘Ͱ
    ߟ͍͑ͯͨॏཁ
    ͳϙΠϯτ✅

    View full-size slide

  28. ղઆΛ͢Δ্Ͱ
    ՄೳͳݶΓ
    Ұͭͷ͜ͱΛઆ໌
    ͍ͨ͠

    View full-size slide

  29. ͔͠͠ɺલఏ஌ࣝ
    ͷੵΈॏͶ΍΢ι
    ͷͳ͍γϯϓϧͳ
    આ໌Λ͢Δͷ͸
    ͱͯ΋೰·͍͠

    View full-size slide

  30. Rubyʹؔ͢Δઆ໌Λ؆୯ͳ
    ಺༰͔Βॱংཱͯઆ໌͢Δ
    ͷ೉͍͠໰୊

    View full-size slide

  31. Rubyʹؔ͢Δઆ໌Λॱংཱͯߟ͑Δ
    • ΠϯτϩμΫγϣϯ
    • จࣈྻ΍਺஋ʹ͍ͭͯͷղઆ
    • ੍ޚߏจʹ͍ͭͯ
    • ഑ྻʹ͍ͭͯ

    :

    View full-size slide

  32. • ΠϯτϩμΫγϣϯ
    • จࣈྻ΍਺஋ʹ͍ͭͯͷղઆ
    • ੍ޚߏจʹ͍ͭͯ
    • ഑ྻʹ͍ͭͯ

    :
    Rubyʹؔ͢Δઆ໌Λॱংཱͯߟ͑Δ

    View full-size slide

  33. puts "Hello, world!"
    puts 1 + 1

    puts "#{10 * 2}"
    ͜͜Βล͸ฏ࿨

    View full-size slide

  34. puts "Hello, world!".upcase
    3.times do |n|
    puts “=> #{n}”
    end
    ్୺ʹݫ͘͠ͳΔ

    View full-size slide

  35. puts "Hello, world!".upcase
    3.times do |n|
    puts “=> #{n}”
    end
    ్୺ʹݫ͘͠ͳΔ
    !?
    !? !?
    !?

    View full-size slide

  36. • ϝιου
    • ʹΫϥεͷઆ໌͕ඞཁ
    • ϒϩοΫ
    • ϒϩοΫҾ਺
    ్୺ʹݫ͘͠ͳΔ

    View full-size slide

  37. ͜ΕΒͷػೳΛ
    จࣈྻ΍਺஋ͷ͍ͭͰʹ
    આ໌͢ΔΘ͚ʹ͸͍͔ͳ͍

    View full-size slide

  38. ಥવ͜ΕΒͷઆ໌Λ࢝ΊͨΒ
    “ύϧεͷϑΝϧγͷ
    ϧγ͕ίΫʔϯͰύʔδ”
    Έ͍ͨʹͳΔ

    View full-size slide

  39. Ͱ͸Ͳ͏͢Δ͔

    View full-size slide

  40. ʢૂ͍ͱͯ͠ʣΦϒδΣΫτࢦ޲ʹ
    ͍ͭͯղઆ͢Δͱ͍͏ΑΓ͸
    ”ΦϒδΣΫτ”΍”ϝιου”ͳͲͷ
    ֓೦͕͋Δ͜ͱΛ஌͍ͬͯͯ΄͍͠

    View full-size slide

  41. ʰ͜ͷੈքʱͰ͸ͦʔ͍͏΋ͷ
    ͩͱʰཧղʱͯ͠΋Β͏

    View full-size slide

  42. Rubyʹؔ͢Δઆ໌Λ؆୯ͳ
    ಺༰͔Βॱংཱͯઆ໌͢Δ
    ͷ೉͍͠໰୊
    ऴΘΓ

    View full-size slide

  43. ϓϩάϥϜతͳҙຯͰΫϥε
    ͷઆ໌͕೉͍͠໰୊

    View full-size slide

  44. ࣗ෼ͰΫϥεΛఆٛ͢Δ·Ͱ͸
    ૉ๿ͳੈք
    ϩʔΧϧม਺Λ࢖͍ɺ૊ΈࠐΈϥΠϒϥϦͱ
    ༡ΜͰ฻Β͍͚ͯ͠Δ

    View full-size slide

  45. Ϋϥεͷఆٛํ๏Λ஌Δͱಥવ
    ੈք͕։͚͗͢Δ໰୊

    View full-size slide

  46. • Πϯελϯεม਺
    • Ϋϥεม਺
    • ϩʔΧϧม਺

    ʢࠓ·ͰԿؾͳ͘࢖͍ͬͯͨม਺ͷਖ਼ମʣ
    • self
    Ξοϓ࢝͠ΊΔม਺ͨͪ

    View full-size slide

  47. • ΠϯελϯεԽ
    • Πϯελϯε/Ϋϥεϝιου
    • ϝιουͷՄࢹੑ
    • ΞΫηοαϝιου
    • ܧঝ
    • Etc
    Ϋϥεʹ·ͭΘΔػೳͨͪ

    View full-size slide

  48. ͪΐͬͱઆ໌͢Δ͜ͱଟ͗͢΍
    ͠ͳ͍͔Ͷʁ

    View full-size slide

  49. Ͳ͏΍ͬͯઆ໌͢Δ͔ɺɺɺ

    View full-size slide

  50. ؤுͬͯઆ໌͢Δ͔͠ͳ͍

    View full-size slide

  51. “ʮҰ൪ͷۙಓ͸ԕճΓͩͬͨʯ
    ʮԕճΓ͕ͦ͜Զͷ࠷୹ͷಓͩͬͨʯ”
    -δϟΠϩɾπΣϖϦ-

    View full-size slide

  52. Ͳ͏ݟͯ΋͜ͷষ͚ͩେมͳϘ
    ϦϡʔϜͰ͢ɻຊ౰ʹ͋Γ͕ͱ
    ͏͍͟͝·ͨ͠

    View full-size slide

  53. ϓϩάϥϜతͳҙຯͰΫϥεͷઆ
    ໌͕೉͍͠໰୊
    ऴΘΓ

    View full-size slide

  54. ;ͭʔʹઆ໌͢Δͱऄ଍ͬΆ͘ͳ
    Δ͚ͲͲ͏ͯ͠΋આ໌͍ͨ͠
    ʢͷͰઆ໌ͨ͠ʣػೳ/࢓૊Έ
    ͦͷଞ

    View full-size slide

  55. จࣈίʔυ
    ࠓͷRuby͸σϑΥϧτΤϯίʔσΟϯά΋
    UTF-8ͷ࣌୅ͳͷͰ;ͭ͏ʹ࢖͏෼ʹ͸ࠔΒͳ͍
    ͔͠͠ɺCSV<->Excelͷѻ͍΍ૉ௚ʹ࡞ΒΕͨ
    Windows࢈ςΩετϑΝΠϧͳͲɺ༉அ͢Δͱ
    UTF-8Ҏ֎ͷ΋ͷʹग़ձ͏͜ͱ΋͋Δ

    View full-size slide

  56. จࣈίʔυ

    View full-size slide

  57. array.map(&:upcase)ͷΞϨ
    ϒϩοΫΛলུͯ͠&:methodΛ౉͢΍ʔͭ
    ਖ਼௚ɺೖ໳ॻͷϨϕϧײͱͯ͠͸ͪΌΜͱͨ͠
    આ໌Λ͢Δʹ͸೉͍͠ʢ΍΍͍͜͠ʣ͚Ͳɺ
    ࣮ίʔυͰ͸;ͭ͏ʹ࢖ΘΕΔ΋ͷͳͷͰ
    આ໌͠ͳ͍Θ͚ʹ΋͍͘·͍

    View full-size slide

  58. array.map(&:upcase)ͷΞϨ

    View full-size slide

  59. ;ͭ͏ʹࠔͬͨ࿩

    View full-size slide

  60. γϯϘϧͷઆ໌
    Ή͔ͣ͗͢͠Ο!!

    View full-size slide

  61. จࣈྻΈ͍͚ͨͩͲจࣈྻ͡Ό
    ͳͯࣝ͘ผࢠʢࣝผࢠͱ͸ʣ
    తʹ࢖͏ΜͩΑɺΈ͍ͨͷΛͳ
    Μͱͳ͘Θ͔ͬͨؾʹͳΔΑ͏
    ͳઆ໌Λ͠ͳͯ͘͸͍͚ͳ͍ͩ
    ͱʁʁʁ

    View full-size slide

  62. ΨνͰࠔ͍ͬͯΔͷͰࡓ͑ͨઆ໌
    ͷ࢓ํ͕͋Ε͹ڭ͍͑ͯͩ͘͞!!1

    View full-size slide

  63. ͓΋͠Ζ͔ͬͨΒ
    ྑ͍δϟϯʂͯ͠Ͷʂʢʁʁʁʣ
    ࠷ޙʹ
    ʮೖ໳ॻΛॻ͘ͷɺͲ͏ʹ͔ͳΔ΍Ζʯͱܰ͘
    ߟ͍͑ͯͨΒࢮ͵΄ͲେมͰͨ͠
    օ͞Μ΋ղઆͰۤ࿑ͨ͠఺΍޻෉͍ͯ͠Δ఺͕
    ͋Ε͹ͥͻڭ͍͑ͯͩ͘͞☺

    View full-size slide

  64. ࢀߟจݙ
    • ͔ΜͨΜRuby
    • https://gihyo.jp/book/2018/978-4-7741-9861-3
    • θϩ͔ΒΘ͔Δ Ruby ௒ೖ໳
    • https://gihyo.jp/book/2018/978-4-297-10123-7
    • Ruby͓ΑͼRailsॻ੶ͷ෼ྨͱҰߟ࡯
    • https://speakerdeck.com/igaiga/dive-into-code-rails-ruby-books
    • Rubyist Hotlinks ʲୈ 1 ճʳ ·ͭ΋ͱΏ͖ͻΖ͞Μ
    • https://magazine.rubyist.net/articles/0001/0001-Hotlinks.html
    • RubyϦϑΝϨϯεϚχϡΞϧ
    • https://docs.ruby-lang.org/ja/latest/doc/index.html

    View full-size slide

  65. ͕࣌ؒ༨ͬͨ༻
    ॻ੶Λࣥච͢Δͱɺվϖʔδͷ౎߹Ͱ༨ന͕ଟ
    ͘ͳͬͯ͠·͏৔߹͕͋Γ·͢
    ͜ͷΑ͏ͳ࣌ɺίϥϜͰຒΊͯ͘ΕʙͱݴΘΕ
    ΔͷͰίϥϜΛॻ͘ͷͰ͕͢ɺׂͱ޷͖উख͔
    ָ͚͍ͯ͠Ͱ͢
    ίϥϜͷதͰ͍͔͓ͭ͘ؾʹೖΓΛ঺հ͠·͢

    View full-size slide

  66. ͍ͬͯ͏͔ϓϩάϥϛ
    ϯάࣗମ͕Ή͔͍ͣ͠

    View full-size slide