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

ruby12

Kuniaki IGARASHI
June 27, 2013
4.2k

 ruby12

Ruby講義第12回
gem(spreadsheet, twitter)

Kuniaki IGARASHI

June 27, 2013
Tweet

Transcript

  1. ܧঝ DMBTT#PPL BUUS@BDDFTTPSUJUMF QSJDF FOE DMBTT.BHB[JF BUUS@BDDFTTPSUJUMF QSJDF OVNCFS FOE

    ͨͱ͑͹#PPLΫϥεͱ.BHB[JOFΫϥε ࡶࢽ Λ࡞Δͱ͠·͢ɻ ผʑʹఆٛΛॻ͍ͯ΋͍͍ͷͰ͕͢ɺڞ௨߲΋ͨ͘͞Μ͋ Γ·͢ɻͦΜͳͱ͖͸ɺܧঝΛ࢖͏ͱ͖ͬ͢Γॻ͚·͢ɻ 
  2. ܧঝ DMBTT#PPL BUUS@BDDFTTPSUJUMF QSJDF FOE DMBTT.BHB[JOF#PPL BUUS@BDDFTTPSOVNCFS FOE DMBTT.BHB[JOF#PPL ͱॻ͘͜ͱͰɺ#PPLΫϥεΛ

    ܧঝͨ͠.BHB[JOFΫϥεΛ ఆٛͰ͖·͢ɻ DMBTT#PPL BUUS@BDDFTTPSUJUMF QSJDF FOE DMBTT.BHB[JOF BUUS@BDDFTTPSUJUMF QSJDF OVNCFS FOE ಉ͡ಈ࡞ ܧঝΛ࢖ͬͨॻ͖ํ ܧঝΛ࢖Θͳ͍ॻ͖ํ 
  3. .BHB[JOF ܧঝ DMBTT#PPL BUUS@BDDFTTPSUJUMF QSJDF FOE DMBTT.BHB[JOF#PPL BUUS@BDDFTTPSOVNCFS FOE ܧঝΛ࢖ͬͨॻ͖ํ

     #PPL BUUS@BDDFTTPSUJUMF QSJDF BUUS@BDDFTTPSOVNCFS #PPLΫϥεΛܧঝͨ͠.BHB[JOFΫϥε͸ɺ#PPLΫϥεͷ࣋ͪ෺Λड ͚ܧ͗·͢ɻ͜ͷྫͷ৔߹͸ɺ#PPLΫϥεͷ BUUS@BDDFTTPSUJUMF QSJDF Λ.BHB[JOFΫϥεͰ΋࢖͑·͢ɻՃ͑ͯɺ.BHB[JOFΫϥεʹ͋Δ BUUS@BDDFTTPSOVNCFS ΋ར༻Ͱ͖·͢ɻ ਤղ
  4. ܧঝ DMBTT#PPL BUUS@BDDFTTPSUJUMF QSJDF FOE DMBTT.BHB[JF#PPL BUUS@BDDFTTPSOVNCFS FOE ྫ͑͹#PPLΫϥεΛܧঝͨ͠ .BHB[JOFΫϥε͸ɺUJUMFͱQSJDFΛ

    ड͚ܧ͍Ͱ͍·͢ɻྫ͑͹ɺˣͷΑ͏ͳ ίʔυΛॻ͘͜ͱ͕Ͱ͖·͢ɻ DMBTTΫϥε໊εʔύʔΫϥε໊ Ϋϥεͷఆٛ FOE ܧঝ͢Δ৔߹ͷॻࣜ εʔύʔΫϥεͱ͸ɺܧঝݩͷ Ϋϥε ਌Ϋϥε Ͱ͢ɻ ܧঝͨ͠Ϋϥε͸ɺ਌ΫϥεͷશͯͷϝιουɺΠϯελϯεม ਺ͳͲΛड͚ܧ͗·͢ɻ NBHB[JOF.BHB[JOFOFX NBHB[JOFUJUMF$BO$BN QNBHB[JOFUJUMF$BO$BN 
  5. .PEVMF ෳ਺ͷΫϥεͰಉ͡ϝιουΛར༻͍ͨ͠ͱ͖ʹNPEVMF Λ࢖͏ͱॏෳͳ͘ॻ͚ΔͷͰศརͰ͢ɻ NPEVMF(SFFUJOH EFGIFMMP QVUT)FMMP FOE FOE DMBTT"MJDF JODMVEF(SFFUJOH

    FOE BMJDF"MJDFOFX BMJDFIFMMPIFMMP DMBTT#PC JODMVEF(SFFUJOH FOE CPC#PCOFX CPCIFMMPIFMMP ΋͠΋IFMMPϝιουͰදࣔ͢ Δ)FMMPΛ͜Μʹͪ͸ʹม͍͑ͨ৔ ߹͸͜ͷϞδϡʔϧ͚ͩมߋ͢Ε͹ྑ͍ 
  6. TQSFBETIFFUHFNԋश B&YDFMϑΝΠϧΛ৽ن࡞੒ SFRVJSFTQSFBETIFFU CPPL4QSFBETIFFU8PSLCPPLOFX TIFFUCPPLDSFBUF@XPSLTIFFU TIFFU< >UFTUJOH CPPLXSJUF FYBNQMFYMT ίʔυΛॻ͍ͨΒ࣮ߦͯ͠ΈͯΈ·͠ΐ͏ɻ

    ࣍ͷϖʔδ΁ଓ͘ HFNJOTUBMMTQSFBETIFFU TQFSFBETIFFUHFNΛΠϯετʔϧ͔ͯ͠Β࣮ߦ͍ͯͩ͘͠͞ɻ ˞4QSFBETIFFU8PSLCPPL ͸ɺҎԼͷΑ͏ͳೖΕࢠʹͳ͍ͬͯΔ தͷΫϥεΛࢦ͢දݱͰ͢ɻ NPEVMF4QSFBETIFFU DMBTT8PSLCPPL  FOE FOE ઌिઆ໌ͨ͠Ϟδϡʔϧʹ͸͜ͷΑ͏ʹ੔ཧ ໊ͯ͠લΛ͚ͭΔ࢖͍ํ΋͋Γ·͢ɻ·ͨ࣍ ճҎ߱ͷߨٛͰग़͖ͯͨࡍʹઆ໌͠·͢ɻ  ˞3VCZͷ৔߹͸ɺ SFRVJSFTQSFBETIFFUͷલʹ SFRVJSFSVCZHFNT ͱॻ͍͍ͯͩ͘͞ɻHFNϥΠϒϥϦΛ࢖͏৔߹ʹ͸ඞཁͰ͢ɻ 3VCZҎ߱Ͱ͸ෆཁͰ͢ɻ
  7. TQSFBETIFFUHFNԋश Bطଘͷ&YDFMϑΝΠϧΛ։͍ͯฤूͯ͠ผ໊Ͱอଘ SFRVJSFTQSFBETIFFU CPPL4QSFBETIFFUPQFO FYBNQMFYMT TIFFUCPPLXPSLTIFFU  QTUSTIFFU< > TIFFU<

    >IFMMP CPPLXSJUF FYBNQMFYMT FYBNQMFYMTΛ։͖ɺը໘ʹ಺༰Λදࣔͨ͠Γɺ ηϧʹ஋Λ௥هͯ͠ผ໊FYBNQMFYMTͱͯ͠อଘ͢ΔαϯϓϧͰ͢ɻ &YDFMϑΝΠϧͷσʔλΛղੳ͢ΔΑ͏ͳ৔߹΍ɺ &YDFMܗࣜͷσʔλΛ࡞Δ৔߹ʹར༻Ͱ͖·͢ɻ FYBNQMFYMT 
  8. UXJUUFSೝূΩʔ ࠷ॳͷ5XJUUFSDPOpHVSFϒϩοΫ͸UXJUUFS։ൃऀαΠτͰ औಘ͢ΔೝূΩʔΛઃఆ͠·͢ɻ SFRVJSFUXJUUFS 5XJUUFSDPOpHVSFEPcDPOpHc DPOpHDPOTVNFS@LFZ999999999999999999 DPOpHDPOTVNFS@TFDSFU999999999999999999 DPOpHPBVUI@UPLFO999999999999999999 DPOpHPBVUI@UPLFO@TFDSFU999999999999999999 FOE

    5XJUUFSTFBSDI OPXQMBZJOH SQQ SFTVMU@UZQFSFDFOU <TUBUVTFT>FBDIEPcTUBUVTc QVUT\TUBUVTGSPN@VTFS^\TUBUVTUFYU^ FOE UXJUUFS"1* ৘ใऔಘૢ࡞૭ޱ Λར༻͢ΔͨΊʹɺ UXJUUFS΁ొ࿥ͯ͠ڐՄΛ΋Β͏ඞཁ͕͋Γ·͢ɻ ͦͷͨΊͷݤ͕ೝূΩʔͰ͢ɻ 
  9. "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU ͭͷτʔΫϯ ͜͜Ͱݴ͏$POTVNFS͸ΞϓϦͷ͜ͱͰ͢ɻ ྫ͑͹ɺ͋ΔΞϓϦʹѱҙ͕͋Δ͜ͱ͕෼͔Γɺ ͦͷΞϓϦʹ͍ͭͯ͸ೝূͤ͞ͳ͍Α͏ʹ͢Δ৔߹ ͸͜ͷͭͷτʔΫϯΛແޮʹ͢Ε͹ःஅͰ͖·͢ɻ $POTVNFSLFZ $POTVNFSTFDSFU "DDFTTUPLFO

    "DDFTTUPLFOTFDSFU ެ։ ඇެ։ ެ։τʔΫϯ͸ JEͷΑ͏ʹ࢖͏ ඇެ։τʔΫϯ͸ QBTTXPSEͷ Α͏ʹ࢖͏ ͜͜Ͱݴ͏"DDFTTUPLFO͸ར༻ ऀਓਓʹൃߦ͞Ε·͢ɻར༻ऀ ͕͜ͷΞϓϦʹର͢ΔೝূΛېࢭ͢ Δ৔߹ʹ͸ɺ͜ͷ̎ͭͷτʔΫϯΛ ແޮʹ͠·͢ɻ 
  10. "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU τʔΫϯͱΞϓϦɺϢʔβʔͷؔ܎ $POTVNFSLFZ $POTVNFSTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU ˞͜ͷྫ͑͸ϑΟΫγϣϯͰ͢ɻ࣮ࡏ͢Δਓ෺ɺΞϓϦͳͲʹ͸Ұ੾ؔ܎͋Γ·ͤΜɻ ύΫυϥ ΞϓϦ

    Ϣʔβʔ "DDFTTUPLFOTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU͸ ΞϓϦ͝ͱʹൃߦ͞ΕΔ "DDFTTUPLFOTFDSFU͸ Ϣʔβʔ͝ͱʹൃߦ͞ΕΔ ར༻ ར༻ UXJUUFS ΞΫηε Ϣʔβʔ 
  11. "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU $POTVNFSLFZ $POTVNFSTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU ˞͜ͷྫ͑͸ϑΟΫγϣϯͰ͢ɻ࣮ࡏ͢Δਓ෺ɺΞϓϦͳͲʹ͸Ұ੾ؔ܎͋Γ·ͤΜɻ ύΫυϥ ΞϓϦ Ϣʔβʔ

    "DDFTTUPLFOTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU͸ ΞϓϦ͝ͱʹൃߦ͞ΕΔ "DDFTTUPLFOTFDSFU͸ Ϣʔβʔ͝ͱʹൃߦ͞ΕΔ ར༻ ར༻ UXJUUFS ΞΫηε Ϣʔβʔ ΞϓϦΛར༻ෆՄʹ͢Δ৔߹ ར༻ෆՄʹ͢ΔΞϓϦͷ$POTVNFSLFZTFDSFUΛແޮԽ͠·͢ɻ ݁ՌతʹɺͦͷΞϓϦΛ࢖͍ͬͯΔϢʔβʔશһ͕ར༻ෆՄʹͳΓ·͢ɻ 
  12. "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU $POTVNFSLFZ $POTVNFSTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU ˞͜ͷྫ͑͸ϑΟΫγϣϯͰ͢ɻ࣮ࡏ͢Δਓ෺ɺΞϓϦͳͲʹ͸Ұ੾ؔ܎͋Γ·ͤΜɻ ύΫυϥ ΞϓϦ Ϣʔβʔ

    "DDFTTUPLFOTFDSFU "DDFTTUPLFO "DDFTTUPLFOTFDSFU $POTVNFSLFZTFDSFU͸ ΞϓϦ͝ͱʹൃߦ͞ΕΔ "DDFTTUPLFOTFDSFU͸ Ϣʔβʔ͝ͱʹൃߦ͞ΕΔ ར༻ ར༻ UXJUUFS ΞΫηε Ϣʔβʔ ͋ΔϢʔβʔͷΈΞϓϦΛར༻ෆՄʹ͢Δ৔߹ ࣗ෼ͷ"DDFTTUPLFOTFDSFUΛແޮԽ͠·͢ɻ ࣗ෼͚ͩ͸ͦͷΞϓϦ͕UXJUUFS΁ΞΫηε͢ΔͷΛෆՄೳʹͰ͖·͢ɻ 
  13. UXJUUFS৘ใऔಘ UXJUUFSͰϢʔβʔ͕ͭͿ΍͍͍ͯΔʮ࠷ۙฉ͍͍ͯΔۂʯΛௐ΂Δ 5XJUUFSTFBSDI OPXQMBZJOH SQQ  SFTVMU@UZQFSFDFOU FBDIEPcTUBUVTc QVUT\TUBUVTGSPN@VTFS^\TUBUVTUFYU^ FOE

    OPXQMBZJOHͱ͍͏ݴ༿ೖΓͷUXFFUΛ࠷৽݅ݕࡧ͢Δ ݅਺ ͜ͷݴ༿ΛؚΉ ͭͿ΍͍ͨϢʔβʔ ͭͿ΍͖಺༰ 5XJUUFSTFBSDIϝιουΛ࢖ͬͯݕࡧ͠·͢ɻ Ҿ਺ʹݕࡧ͍ͨ͠಺༰Λ౉͠·͢ɻ ݅औಘͨͭ͠Ϳ΍͖͸ɺ݅ͣͭϒϩοΫ͕࣮ߦ͞Εɺ ϒϩοΫ಺ม਺TUBUVTʹ୅ೖ͞Ε·͢ɻ 
  14. ԋशղઆɹจࣈྻදࣔ 3VCZʹ͸छྨͷจࣈྻͷදݱํ๏͕͋Γ·͢ɻ μϒϧΫΦʔτ  ͱγϯάϧΫΦʔτ  Ͱ͢ɻ લͷϖʔδͰઆ໌ͨ͠ม਺ͷத਎Λදࣔ͢Δ৔߹͸μϒϧΫΦʔτΛ ࢖͏ඞཁ͕͋Γ·͢ɻ OBNFJHBSBTIJ

    QVUT"VUIPS\OBNF^"VUIPSJHBSBTIJ ม਺OBNFͷத਎͕දࣔ͞ΕΔ OBNFJHBSBTIJ QVUT"VUIPS\OBNF^"VUIPS\OBNF^ ม਺OBNFͷத਎͕දࣔ͞Εͣɺͦͷ··ग़ྗ͞ΕΔ μϒϧΫΦʔτɿ\ม਺໊^ͱॻ͘ͱม਺ͷத਎Λදࣔ γϯάϧΫΦʔτɿ\ม਺໊^ͱॻ͘ͱͦͷ··දࣔ 
  15. ԋशղઆҾ਺ͷ)BTIͷলུܗ 5XJUUFSTFBSDI OPXQMBZJOH SQQ SFTVMU@UZQFSFDFOU ͜ͷ෦෼ɺݟ׳Εͳ͍ॻ͖ํΛ͍ͯ͠·͢ɻ 5XJUUFSTFBSDI OPXQMBZJOH \SQQ SFTVMU@UZQFSFDFOU^

    লུ͠ͳ͍Ͱॻ͘ͱҎԼͷΑ͏ʹͳΓ·͢ɻ ൪໨ͷҾ਺͸จࣈྻ ൪໨ͷҾ਺͸)BTIͰ\^Λলུ 3VCZͰΑ͘࢖ΘΕΔςΫχοΫͰɺͨͱ͑͹ෳ਺ͷΦϓγϣϯΛҾ ਺ͱͯ͠౉͍ͨ͠ͱ͖ʹ)BTIΛ౉͢͜ͱ͕͋Γ·͢ɻΩʔ͕આ໌จ ͷ໾໨Λͯ͘͠ΕͯಡΈ΍͍͔͢ΒͰ͢ɻ ͦͷࡍʹᐆດʹͳΒͳ͚Ε͹)BTIͷ\^Λলུͯ͠ॻ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UQDVSMIBYYTFDB΁ΞΫηεͯ͠ɺ ɹԼઢ෦ͷϑΝΠϧΛӈΫϦοΫ໊ͯ͠લΛ෇͚ͯอଘ ҎԼͷίϚϯυΛଧͪɺ؀ڥม਺44-@$&35@'*-&ʹͦͷύεΛઃఆ ։͍͍ͯΔίϚϯυϓϩϯϓτ͸Ұ౓ดͯ͡։͖ͳ͓͢ TFUY44-@$&35@'*-&$=3BJMT*OTUBMMFS=DBDFSUQFN 
  18. NBDͰҎԼͷΑ͏ͳΤϥʔ͕ग़Δ৔߹ͷରԠํ๏ VTSCJO3VCZMJCSVCZOFUIUUQSCJOADPOOFDU 44-@DPOOFDUSFUVSOFEFSSOPTUBUF44-WSFBETFSWFSDFSUJpDBUF #DFSUJpDBUFWFSJGZGBJMFE 5XJUUFS&SSPS$MJFOU&SSPS 3VCZ͕࢖͏44-ূ໌ॻ ηΩϡϦςΟͷͨΊʹඞཁ ͷظݶ͕੾ΕͨͨΊʹൃ ੜ͢Δ໰୊Ͱ͢ɻ ূ໌ॻϑΝΠϧ͕͋ΔύεΛௐ΂·͢ɻ

    ʢ݁Ռ͕VTSMPDBMFUDPQFOTTMDFSUQFNͷ৔߹ͷྫΛҎԼΛॻ͖·͢ɻ ଞͷ݁Ռͷ৔߹͸ҎԼͷ৭෇͖ͷ෦෼Λஔ͖׵͍͑ͯͩ͘͞ɻʣ طଘͷূ໌ॻͷόοΫΞοϓΛͱΓ·͢ɻ ҎԼͷίϚϯυͰূ໌ॻϑΝΠϧΛμ΢ϯϩʔυ͠·͢ɻ μ΢ϯϩʔυͨ͠৽͍͠ূ໌ॻͰஔ͖׵͑·͢ɻ ͜ΕͰΤϥʔ͕ग़ͳ͘ͳΓ·͢ɻ TVEPDQVTSMPDBMFUDPQFOTTMDFSUQFNVTSMPDBMFUDPQFOTTMDFSUQFNCBL  SVCZSPQFOTTMFQ0QFO44-9%&'"6-5@$&35@'*-& DVSM0IUUQDVSMIBYYTFDBDBDFSUQFN NWDBDFSUQFNVTSMPDBMFUDPQFOTTMDFSUQFN
  19. UXJUUFSHFNԋश ݕࡧޠOPXQMBZJOHͷ෦෼Λ͍Ζ͍Ζม࣮͑ͯߦͯ͠Έ͍ͯͩ͘͞ɻ ʢUXJUUFS"1*͸୯Ґ࣌ؒ಺ʹ࣮ߦͰ͖Δճ਺͕ݶΒΕ͍ͯΔͷͰɺ࣮ ߦ͗͢͠Δͱ࣌ؒఔ౓࣮ߦͰ͖ͳ͘ͳΓ·͢ɻ ೔ຊޠʹ͢Δ৔߹͸ϚδοΫίϝϯτ DPEJOHVUG Λ๨Εͣʹɻ ·ͨɺ8JOEPXTͰ݁Ռ͕จࣈԽ͚͢Δ৔߹͸ɺҎԼͷΑ͏ʹϑΝΠϧ SFTVMUUYU΁ॻ͖ग़ͯ͠ΤσΟλͰ։͘ɺΛࢼͯ͠Έ͍ͯͩ͘͞ɻ SFRVJSFUXJUUFS

    5XJUUFSDPOpHVSFEPcDPOpHc DPOpHDPOTVNFS@LFZ999999999999999999 DPOpHDPOTVNFS@TFDSFU999999999999999999 DPOpHPBVUI@UPLFO999999999999999999 DPOpHPBVUI@UPLFO@TFDSFU999999999999999999 FOE 5XJUUFSTFBSDI OPXQMBZJOH SQQ SFTVMU@UZQFSFDFOU <TUBUVTFT>FBDIEPcTUBUVTc QVUT\TUBUVTGSPN@VTFS^\TUBUVTUFYU^ FOE SVCZUXJUUFSSCSFTVMUUYU