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

ruby13

 ruby13

Ruby講義 第13回
2013.7.11
sinatra

Kuniaki IGARASHI

July 04, 2013
Tweet

More Decks by Kuniaki IGARASHI

Other Decks in Technology

Transcript

  1. 8JOEPXTͰҎԼͷΑ͏ͳΤϥʔ͕ग़Δ৔߹ͷରԠํ๏ $3BJMT*OTUBMMFS3VCZMJCSVCZOFUIUUQSCJOADPOOFDU 44-@DPOOFDUSFUVSOFEFSSOPTUBUF44-WSFBETFSWFSDFSUJpDBUF #DFSUJpDBUFWFSJGZGBJMFE 5XJUUFS&SSPS$MJFOU&SSPS 3VCZ͕࢖͏44-ূ໌ॻ ηΩϡϦςΟͷͨΊʹඞཁ ͷظݶ͕੾ΕͨͨΊʹൃ ੜ͢Δ໰୊Ͱ͢ɻ ҎԼ͔Βূ໌ॻϑΝΠϧΛ%-ͯ͠

    ɹ$ˇ3BJMT*OTUBMMFSϑΥϧμʹDBDFSUQFNͱ͍͏໊લͰอଘ͠·͢ɻ IUUQDVSMIBYYTFDBDBDFSUQFN IUUQDVSMIBYYTFDB΁ΞΫηεͯ͠ɺ ɹԼઢ෦ͷϑΝΠϧΛӈΫϦοΫ໊ͯ͠લΛ෇͚ͯอଘ ҎԼͷίϚϯυΛଧͪɺ؀ڥม਺44-@$&35@'*-&ʹͦͷύεΛઃఆ ։͍͍ͯΔίϚϯυϓϩϯϓτ͸Ұ౓ดͯ͡։͖ͳ͓͢ TFUY44-@$&35@'*-&$=3BJMT*OTUBMMFS=DBDFSUQFN 
  2. NBDͰҎԼͷΑ͏ͳΤϥʔ͕ग़Δ৔߹ͷରԠํ๏ VTSCJO3VCZMJCSVCZOFUIUUQSCJOADPOOFDU 44-@DPOOFDUSFUVSOFEFSSOPTUBUF44-WSFBETFSWFSDFSUJpDBUF #DFSUJpDBUFWFSJGZGBJMFE 5XJUUFS&SSPS$MJFOU&SSPS 3VCZ͕࢖͏44-ূ໌ॻ ηΩϡϦςΟͷͨΊʹඞཁ ͷظݶ͕੾ΕͨͨΊʹൃ ੜ͢Δ໰୊Ͱ͢ɻ ূ໌ॻϑΝΠϧ͕͋ΔύεΛௐ΂·͢ɻ

    ʢ݁Ռ͕VTSMPDBMFUDPQFOTTMDFSUQFNͷ৔߹ͷྫΛҎԼΛॻ͖·͢ɻ ଞͷ݁Ռͷ৔߹͸ҎԼͷ৭෇͖ͷ෦෼Λஔ͖׵͍͑ͯͩ͘͞ɻʣ طଘͷূ໌ॻͷόοΫΞοϓΛͱΓ·͢ɻ ҎԼͷίϚϯυͰূ໌ॻϑΝΠϧΛμ΢ϯϩʔυ͠·͢ɻ μ΢ϯϩʔυͨ͠৽͍͠ূ໌ॻͰஔ͖׵͑·͢ɻ ͜ΕͰΤϥʔ͕ग़ͳ͘ͳΓ·͢ɻ TVEPDQVTSMPDBMFUDPQFOTTMDFSUQFNVTSMPDBMFUDPQFOTTMDFSUQFNCBL  SVCZSPQFOTTMFQ0QFO44-9%&'"6-5@$&35@'*-& DVSM0IUUQDVSMIBYYTFDBDBDFSUQFN NWDBDFSUQFNVTSMPDBMFUDPQFOTTMDFSUQFN
  3. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश  ҎԼͷίʔυΛॻ͍ͯ޷͖ͳ໊લͰอଘ͠·͢ɻʢྫ͑͹TFSWFSSCʣ SFRVJSFTJOBUSB HFUEP )FMMPXPSME FOE ϒϥ΢β͔ΒҎԼͷ63-΁ΞΫηε͠·͢ɻ HFNJOTUBMMTJOBUSB HFNΛΠϯετʔϧ͠·͢ɻ

    ࣮ߦ͠·͢ɻӈԼͷΑ͏ͳද͕ࣔग़·͢ɻ SVCZTFSWFSSC 4JOBUSBIBTUBLFOUIFTUBHFPOGPS EFWFMPQNFOUXJUICBDLVQGSPN5IJO 5IJOXFCTFSWFS WDPEFOBNF4USBJHIU3B[PS .BYJNVNDPOOFDUJPOTTFUUP -JTUFOJOHPOMPDBMIPTU $53- $UPTUPQ IUUQMPDBMIPTU )FMMPXPSMEͱදࣔ͞ΕΕ͹੒ޭͰ͢ɻ ˞ίʔυΛมߋͨ͠৔߹͸Ͱ࣮ߦ͍ͯ͠ΔTIFMMΛ$USM DͰఀࢭͤ͞ɺ࠶࣮ߦ͠·͢ɻ  8JO؀ڥͰऴྃ͠ͳ͍৔߹ɺ$USM 1"64&Λࢼ͍ͯͩ͘͠͞ɻʣ 
  4. 8FC4FSWFS 8FC"QQ #SPXTFS ϦΫΤετ Ϩεϙϯε 63-IUUQMPDBMIPTU 63-MPDBMIPTU͸ࣗ෼ͷϚγϯ SFRVJSFTJOBUSB HFUEP )FMMPXPSME

    FOE 8FC"QQ ΞϓϦ ͷ෦෼͕Έͳ͞Μ͕ॻ͍ͨίʔυͰ͢ɻ 8FC4FSWFS͸TJOBUSBͱ3VCZ͕͏·͍͜ͱ΍ͬͯ͘Ε·͢ɻ ࣗ෼ͷ1$ MPDBMIPTU͸ࣗ෼ͷ1$Λද͢ಛผͳΞυϨεͰ͢ɻ Ͱ͸ɺ63-ͷΑΓޙΖͷͱ͸ԿͰ͠ΐ͏͔ʁ 
  5. MPDBMIPTU ಛผͳΞυϨεͰ͢ɻࣗ෼ͷϚγϯΛࢦ͠·͢ɻ IUUQMPDBMIPTU 63-ͷઆ໌  ϙʔτ൪߸Ͱ͢ɻ൪ϙʔτΛࢦ͠·͢ɻ ීஈ͸ࢦఆ͠ͳ͍͜ͱ͕ଟ͍Ͱ͢ɻࢦఆ͠ͳ͍ͱ൪ϙʔτʹͳΓ·͢ɻ ͭ·ΓɺҰൠతͳ8FCΞϓϦ͸൪ϙʔτͰՔಇ͍ͯ͠·͢ɻ ΞυϨε ϙʔτ

    63-ͷΑΓޙΖ͸ϙʔτΛද͠·͢ɻ ϙʔτ͸ɺಉ͡ΞυϨε಺Ͱ௨৴ઌΛಛఆ͢Δ൪߸Ͱ͢ɻ ྫ͑͹ɺΞυϨε͕Ӻͷ໊લɺϙʔτ͕ӺͷϗʔϜ˓൪ઢɺ ͱΠϝʔδ͢Δͱ෼͔Γ΍͍͔͢΋͠Ε·ͤΜɻ 
  6. 8FC4FSWFS 8FC"QQ #SPXTFS ϦΫΤετ Ϩεϙϯε 63-IUUQMPDBMIPTU ઌ΄Ͳ࡞ͬͨ8FCΞϓϦͷಈ࡞ུ֓ SFRVJSFTJOBUSB HFUEP )FMMPXPSME

    FOE ࣍͸8FCΞϓϦͷಈ͖Λৄ͘͠ݟ͍͖ͯ·͢ MPDBMIPTU൪ϙʔτʹདྷͨ ϦΫΤετΛ8FC"QQ΁ಧ͚·͢ 
  7. 8FC4FSWFS 8FC"QQ #SPXTFS ϦΫΤετ Ϩεϙϯε 63-IUUQMPDBMIPTU 8FCΞϓϦͷಈ࡞ SFRVJSFTJOBUSB HFUEP )FMMPXPSME

    FOE MPDBMIPTU൪ϙʔτʹདྷͨ ϦΫΤετΛ8FC"QQ΁ಧ͚·͢ 63-ͷΞυϨεͱϙʔτΑΓ ޙΖͷ෦෼Λύεͱݴ͍·͢ɻ ͜ͷ৔߹ɺύε͸ʹͳΓ·͢ɻ ύε͕ͷϦΫΤετʹରͯ͠ )FMMPXPSMEͱ͍͏Ϩεϙϯε Λฦ͢8FCΞϓϦͱͯ͠ಈ࡞͠·͢ ड͚औͬͨϨεϙϯεΛදࣔ 
  8. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश KQ ҎԼͷίʔυΛॻ͍ͯ޷͖ͳ໊લͰอଘ͠·͢ɻ KQSCͱ͠·͢ DPEJOHVUG SFRVJSFTJOBUSB HFUKQEP ͜Μʹͪ͸ʂ FOE ϒϥ΢β͔ΒҎԼͷ63-΁ΞΫηε͠·͢ɻ

    ࣮ߦ͠·͢ɻ SVCZKQSC 4JOBUSBIBTUBLFOUIFTUBHFPOGPS EFWFMPQNFOUXJUICBDLVQGSPN5IJO 5IJOXFCTFSWFS WDPEFOBNF4USBJHIU3B[PS .BYJNVNDPOOFDUJPOTTFUUP -JTUFOJOHPOMPDBMIPTU $53- $UPTUPQ IUUQMPDBMIPTUKQ ͜Μʹͪ͸ʂͱදࣔ͞ΕΕ͹੒ޭͰ͢ɻ લͷखॱͰ࣮ߦͨ͠8FCαʔόʔ͕ىಈ͍ͯ͠Δ৔߹͸$USM DͰఀࢭͤ͞·͢ɻ  8JO؀ڥͰऴྃ͠ͳ͍৔߹ɺ$USM 1"64&Λࢼ͍ͯͩ͘͠͞ɻʣ ˞ίʔυΛॻ͖׵͑ͨ৔߹΋Ұ౓ఀࢭˠ࣮ߦ͢Δඞཁ͕͋Γ·͢ɻ ʢϑΝΠϧ໊͸ɺͲΜͳ໊લͰ΋ߏ͍·ͤ Μɻผͷ໊લͰอଘͯ͠΋େৎ෉Ͱ͢ɻʣ 
  9. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश KQ ղઆ HFUͷޙΖʹॻ͘จࣈྻͷϦΫΤετ63-ύεʹԠ౴͠·͢ɻ DPEJOHVUG SFRVJSFTJOBUSB HFUKQEP ͜Μʹͪ͸ʂ FOE ͜ͷίʔυͷ৔߹͸

    63-IUUQMPDBMIPTUKQ ύεͷ෦෼͕KQ ʹΞΫηε͞Εͨ৔߹ʹ ͜Μʹͪ͸ʂ ΛϨεϙϯεͱͯ͠ฦ͠·͢ɻ  ˞ͪͳΈʹɺ͜Μʹͪ͸ʂͷ෦෼ΛI͜Μʹͪ͸ʂIͱॻ͘ͱ େ͖ͳจࣈͰදࣔͤ͞Δ͜ͱ͕Ͱ͖·͢ɻ͜Ε͸ɺ)5.-ͱ͍͏ݴޠͷจ๏Ͱɺ ϒϥ΢β͸)5.-Ͱॻ͔ΕͨιʔείʔυΛղऍͯ͠දࣔ͠·͢ɻ )5.-ʹ͍ͭͯɺৄ͘͠͸ౙֶظʹઆ໌͠·͢ɻ
  10. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश UJNF ҎԼͷίʔυΛॻ͍ͯ޷͖ͳ໊લͰอଘ͠·͢ɻ UJNFSCͱ͠·͢ɻ SFRVJSFTJOBUSB HFUUJNFEP 5JNFOPXUP@T FOE ϒϥ΢β͔ΒҎԼͷ63-΁ΞΫηε͠·͢ɻ ࣮ߦ͠·͢ɻ

    SVCZUJNFSC 4JOBUSBIBTUBLFOUIFTUBHFPOGPS EFWFMPQNFOUXJUICBDLVQGSPN5IJO 5IJOXFCTFSWFS WDPEFOBNF4USBJHIU3B[PS .BYJNVNDPOOFDUJPOTTFUUP -JTUFOJOHPOMPDBMIPTU $53- $UPTUPQ IUUQMPDBMIPTUUJNF ͷΑ͏ʹݱࡏ࣌ࠁ͕දࣔ͞ΕΕ͹੒ޭͰ͢ɻ લͷखॱͰ࣮ߦͨ͠8FCαʔόʔ͕ىಈ͍ͯ͠Δ৔߹͸$USM DͰఀࢭͤ͞·͢ɻ  8JO؀ڥͰऴྃ͠ͳ͍৔߹ɺ$USM 1"64&Λࢼ͍ͯͩ͘͠͞ɻʣ ˞ίʔυΛॻ͖׵͑ͨ৔߹΋Ұ౓ఀࢭˠ࣮ߦ͢Δඞཁ͕͋Γ·͢ɻ   ݱࡏ࣌ࠁΛදࣔͤ͞Δ8FCΞϓϦΛ࡞ͬͯΈ·͠ΐ͏ɻ 
  11. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश UJNF ղઆ ͜ͷ՝୊͔Βɺ5JNFOPXͷΑ͏ͳ3VCZίʔυΛ࣮ߦͨ݁͠ՌΛ ϒϥ΢βͰදࣔ͢Δํ๏Λֶ΂·͢ɻ SFRVJSFTJOBUSB HFUUJNFEP 5JNFOPXUP@T FOE 5JNFOPX͸ݱࡏ࣌ࠁΛ5JNFDMBTTΦϒ

    δΣΫτͰฦ͠·͢ɻ UP@TϝιουΛ࢖͏ͱɺ4USJOHDMBTTΦ ϒδΣΫτ΁ม׵͞Ε·͢ɻ 4USJOHΦϒδΣΫτͰ͋Ε͹ϒϥ΢β΁දࣔͰ͖ΔͷͰɺ UP@TϝιουͳͲͰม׵͢Δ͜ͱͰॲཧ݁ՌΛදࣔ͢Δ͜ͱ͕Ͱ͖·͢ɻ ·ͨɺ5JNFOPX͸ϦΫΤετ͝ͱʹ࣮ߦ͞ΕΔͷͰɺ Ϧϩʔυ͢Δ͝ͱʹͦͷ࣌఺ͷݱࡏ࣌ࠁ͕දࣔ͞Ε·͢ɻ 
  12. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश ύε ҎԼͷίʔυΛॻ͍ͯ޷͖ͳ໊લͰอଘ͠·͢ɻ QBUISCͱ͠·͢ɻ SFRVJSFTJOBUSB HFUXPSEEP QBSBNT<XPSE> FOE ϒϥ΢β͔ΒҎԼͷ63-΁ΞΫηε͠·͢ɻ ࣮ߦ͠·͢ɻ

    SVCZQBUISC 4JOBUSBIBTUBLFOUIFTUBHFPOGPS EFWFMPQNFOUXJUICBDLVQGSPN5IJO 5IJOXFCTFSWFS WDPEFOBNF4USBJHIU3B[PS .BYJNVNDPOOFDUJPOTTFUUP -JTUFOJOHPOMPDBMIPTU $53- $UPTUPQ IUUQMPDBMIPTUIJ લͷखॱͰ࣮ߦͨ͠8FCαʔόʔ͕ىಈ͍ͯ͠Δ৔߹͸$USM DͰఀࢭͤ͞·͢ɻ  8JO؀ڥͰऴྃ͠ͳ͍৔߹ɺ$USM 1"64&Λࢼ͍ͯͩ͘͠͞ɻʣ ˞ίʔυΛॻ͖׵͑ͨ৔߹΋Ұ౓ఀࢭˠ࣮ߦ͢Δඞཁ͕͋Γ·͢ɻ IJͱ͍͏ύεʹΞΫηε͞ΕΕ͹IJ͕ɺ CPPLͱ͍͏ύεͳΒCPPL͕දࣔ͞Ε·͢ɻ ΞΫηεͨ͠ύεΛදࣔͤ͞Δ8FCΞϓϦΛ࡞ͬͯΈ·͠ΐ͏ɻ 
  13. TJOBUSBHFNΛ࢖ͬͨ8FCΞϓϦ࡞Γԋश ύε ղઆ HFUޙͷจࣈྻͷதʹXPSEͷΑ͏ʹγϯϘϧΛॻ͘ͱɺ ϦΫΤετ͞ΕͨύεΛQBSBNT<XPSE>Ͱड͚औΕ·͢ɻ SFRVJSFTJOBUSB HFUXPSEEP QBSBNT<XPSE> FOE IUUQMPDBMIPTUIJ

    ͜ΕΛԠ༻͢Δͱɺྫ͑͹݂ӷܕ઎͍ͳͲɺ ΞΫηε͞Εͨ63-ʹԠͯ͡දࣔΛม͑ΔΞϓϦΛ࡞Ε·͢ɻ ͕࣌ؒ͋Δਓ͸νϟϨϯδͯ͠Έ͍ͯͩ͘͞ɻ ্هͷ63-ͰΞΫηεͨ͠৔߹ɺ QBSBNT<XPSE>͸IJΛฦ͠·͢ɻ ˞͜͜ͰͷXPSE͸೚ҙͷ໊લʹͰ͖·͢ɻ HFUGPPEPʙͱॻ͍ͨ৔߹͸ QBSBNT<GPP>ͰύεΛऔΕ·͢ɻ