ã APIãã¶ã¤ã³ã±ã¼ã¹ã¹ã¿ã㣠ãã¨ããæ¬ãé æ´ããã®ã§èªãã§ã¿ãã
ã©ã¤ãã©ãªä½è ã«åãã¦
ãã®æ¬ã¯Rubyæ¨æºã©ã¤ãã©ãªãé¡æã«ãã¦ãåããããããå¤æ§ãªæ©è½ããµãã¼ããã¦ãäºææ§ãä¿ã¤APIã®è¨è¨ãããã«ã¯ã©ã®ããã«èããã¹ãããæãã¦ãããã
ããã§APIã¨è¨ã£ã¦ããã®ã¯ãä¸è¬çãªRubyã®ã¯ã©ã¹ã¨ãªãã¸ã§ã¯ãã¨ã¡ã½ããããæãã©ã¤ãã©ãªãã©ããã¶ã¤ã³ããããã¨ãã話ã§ããã å¥ã«Chef RecipeãRSpec DSLã®ãããªã¡ãã£ã¨å¤ãã£ãDSLãè¨è¨ããã¨ããããã話ã§ã¯ãªãã確ãã«ãã®ç¨®ã®è¨èªå DSLã®ãã¶ã¤ã³ã«ã¯åºæã®ã»ã³ã¹ãå¿ è¦ã¨ããããã Ruby DSL Handbook ãªãã¦æ¬ãæ¸ããã¦ããããã«å®è£ ã«ããã£ã¦ããã種ã®ãã¯ããã¯ãå¿ è¦ãªã®ã確ãã ãã§ãããã以å¤ã®ããµã¤ããã®ã©ã¤ãã©ãªã®ãã¶ã¤ã³ã¯æããã¦ç°¡åã ãããã é©åãªç²åº¦ã®ã¯ã©ã¹ãå®ç¾©ãããå¿ è¦ãªæ©è½ã«åããã¦ã¡ã½ãããå®ç¾©ãããã¡ã½ããã®å¼æ°ã¯ä½ã§ããã¹ãããå¼æ°ã®é åºã¯? å¼æ°ãå¤ããã¦ä½¿ãã®ã大å¤ã«ãªã£ã¦ããªããããã®ã¡ã½ããåã¯ä»ã®ä¼¼ãæ©è½ããé¡æ¨å¯è½ã ããããæ©è½ã追å ããã¨ããã©ããã£ã¦å¾æ¹äºææ§ãä¿ã¦ã°è¯ãã®ããäºææ§ãç ´ã£ã¦ã§ãæ¹åãã¹ãã¨å¤æããã«ããã£ã¦ã¯ä½ãèæ ®ããã°è¯ãã®ãã æ¬æ¸ãæ±ãã®ã¯ãããã話é¡ã ã
ã¡ãªã¿ã«ãèè
ã®akr(ç°ä¸å²)ããã¯Rubyã©ã¤ãã©ãªè¨è¨ã®ç¬¬ä¸äººè
ã¨è¨ã£ã¦ãè¯ãã ããã
é·ãã«æ¸¡ã£ã¦Rubyã³ã¢ããã³æ¨æºæ·»ä»ã©ã¤ãã©ãªã®éçºãå¹
åºãæããã¦ãããä»ã®Rubyã³ãã¥ããã£ã«ããã©ã¤ãã©ãªè¨è¨ã®æ
£ç¿ãåºç¤ã¥ãã人ã
ã®ï¼äººã ã
ä¸ã§ãæ¬æ¸ã§é¡æã«ä¸ãã£ã¦ãã IO
ã¯ã©ã¹ã Time
ã¯ã©ã¹ãããã³ socket
ã©ã¤ãã©ãªã®è¨è¨ã«ããã¦ãããã¤ãã®å°é£ãªèª²é¡ã解決ãã¦ããã
æ¬æ¸ãèªããã¨ã§é¡æã«ãªã£ã¦ããRubyã®æ¨æºã©ã¤ãã©ãªã¸ã®ç解ã¯æ·±ã¾ãã ããããèªåã§Rubyã©ã¤ãã©ãªãæ¸ãã¨ãã®èãæ¹ã®åèã«ããªãã ããã ãã£ã¨ä¸è¬ã«ä»»æã®è¨èªã§ã©ã¤ãã©ãªã®APIããã¶ã¤ã³ããã¨ãã®å©ãã«ããªãã ããã
ã©ã¤ãã©ãªç§»æ¤è ã«åãã¦
æ¬æ¸ã¯ã¾ããã©ã¤ãã©ãªã移æ¤ããç©èªã¨ãã¦èªããã¨ãã§ããã
Rubyã®æ¨æºã©ã¤ãã©ãªããã¨ã« IO
ã socket
ã¯Cæ¨æºã©ã¤ãã©ãªãUNIXã·ã¹ãã ã³ã¼ã«ãæèãã¦ãã¶ã¤ã³ããã¦ããã
ãã£ã¦ãããã®ã©ã¤ãã©ãªãCããRubyã¸ã®ç§»æ¤ã¨æãããã¨ãã§ããã ããã
ãã®ãããªã©ã¤ãã©ãªã®ç§»æ¤ã«å½ãã£ã¦ã¯ãå¹¾ã¤ãã®ãã¶ã¤ã³ã®é¸æè¢ããããä¸çªåç´ãªã®ã¯ãå ã®ã©ã¤ãã©ãªã®APIãå¼ãåããã¨ã ããã å©ç¹ã¨ãã¦ã¯å ã®ã©ã¤ãã©ãªãç¥ã£ã¦ããã°ç§»æ¤å ã®å¦ç¿ã容æãªãã¨ãæãããããããã«ãã¶ã¤ã³ã«ãã¾ãé ã使ããªãã¦æ¸ãã ä¸æ¹ã§ãããã¯ä¸è¬ã«ãã¾ã使ããããAPIã«ã¯ãªããªãã è¨èªãã¨ã«æã¾ããã¨ã©ã¼ã®è¿ãæ¹ãé¢æ°ã®å½åæ £ç¿ãç°ãªãããããããæ £ç¿ãæ¯ããè¨èªã®ç¹æ§èªä½ãéçåä»ãã®æãç¡ãããçå½å¤ã®å®ç¾©ããä½ãããéãã®ã ã
ãã®å¯¾æ¥µã«å½ããã¢ããã¼ãã¯ãã»ã¼åãæ©è½ãæä¾ããã©ã¤ãã©ãªãã¼ããããã¶ã¤ã³ãããã¨ã ââ ãã¯ãã移æ¤ãã¨ã¯è¨ãããããããããªããã å©ç¹ã¨ãã¦ã¯ãããé©åã«ãã¶ã¤ã³ã§ããã°ç§»æ¤å ã®è¨èªã®ããã°ã©ãã«ã¨ã£ã¦ç解ãããã使ããããAPIãå¾ãããã ä¸æ¹ã§ã移æ¤å ã®ã©ã¤ãã©ãªãã¶ã¤ã³ããã®é¡æ¨ãåããªãã®ã§å¦ç¿ã³ã¹ããããã£ã¦é«ãä»ãå¯è½æ§ãããã
ã§ã¯Rubyã¯ãakrããã¯ããã®ä¸¡æ¥µã®éã§ã©ã®ãããªé¸æããã¦ããã ããããæ¬æ¸ã¯ãã®æ´å²ãèªã£ã¦ããã
ãããã移æ¤ãããã£ã¦
話ã¯å¤ããããç§ã¯ãã®æ°å¹´ã¨ãããã®ãæ¥åã§ã¯Ruby以å¤ã®è¨èªã§éçºããããã¨ãå¤ãã ãã£ã±ãC++ãPythonãGo, æã«ã¯Javaã触ãããããå¾ãPHPã触ããã¨ãããã
ãããã®è¨èªã§éçºããéç¨ã§ãã°ãã°Rubyã®ã©ã¤ãã©ãªããã¬ã¼ã ã¯ã¼ã¯ããã¼ã«ããå½±é¿ãåããã¨æãããã®ãç®ã«ãããã¨ããã£ãã ãã¨ã«åæã¸ã®RailsãActiveRecordã®å½±é¿ã¯èãããã®ããããæ¨ä»ã§ã¯Railsã常ã«Webã¢ããªã±ã¼ã·ã§ã³éçºã®ç¬¬ä¸é¸æè¢ã¨ã¯éããªããªã£ã¦ãã¦ããã®ããã²ã¨ãã«Railsã®è¯ããä»ã®ãã¬ã¼ã ã¯ã¼ã¯ã«åºãåãå ¥ãããã¦ãã¯ãç¾ä»£webã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã§ã¯å½ããåã®æ§è³ªã¨ãªã£ã¦ããããã§ããã
ãã®ããã«Rubyã³ãã¥ããã£ã®ææãä»ããåèã«ãããã®ã¯èªããããããããä¸æ¹ã§ããããããããããã¨ãããã ããããããã®ã¯ãRubyã®ã©ã¤ãã©ãªããã¬ã¼ã ã¯ã¼ã¯ã®å£åã³ãã¼ãç®ã«ããã¨ãã ã
ãã¨ãã°Railsã®å£åã³ãã¼ã§ããã ãã¾ã©ãRailsã«å½±é¿ãåãããã¬ã¼ã ã¯ã¼ã¯ã¯çãããªããããã¦ãæããã¦ãã®Railsã®æ©è½ã¯æ¬å½ã«ãã®è¨èªã«åãã¦ããã ãããã ããããRailsã¯ãã«ã¹ã¿ãã¯ãã¤å¯çµåãªæ¥µç«¯ãªãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦ç»å ´ãããRailsã«ã¯(å½æã®webã¢ããªã±ã¼ã·ã§ã³ã®)ãã¹ã¦ãæã£ã¦ãã¦ããã®æ§æè¦ç´ ãå¯ã«çµåãã¦ãã代ããã«ãRailã«ä¹ã£ã¦ãããéãã«ããã¦ã¯æ¥µå°ã®ã³ã¼ãéã§ãããããã¨ãç°¡åã«ã§ããã æ®éã«èããã°æ§æè¦ç´ ãå¯çµåãªã®ã¯æªã ããRailsã¯å¯çµåç±æ¥ã®é£ç¹ããã¾ãè£ããããªæ©è½ãæä¾ãã¦ãã¦ãã¾ãRubyèªä½ã®æè»æ§ããã£ã¦(ããã¨ãªãã°ã¢ã³ãã¼ããããã¦ã§ã)åé¡ã解決ãããã¨ãã§ããã ãããªã«ãå¯çµåãªãã¬ã¼ã ã¯ã¼ã¯ãã¾ã¨ãã«ä½¿ãç©ã«ãªããã¨èªä½ãä¿¡ããããããã©ãããã¾ããã©ã³ã¹ã¨Rubyã®åã§ä¸æè°ã¨ä½¿ããããã®ãRailsã§ããã
ã ã¨ããã°ãRubyãããæè»æ§ã«å£ã大æµã®è¨èªã«ã¨ã£ã¦Railsã®æ¡ã£ãé¸æã¯é©åã§ãªããã¾ãããRailsã®ãµãã»ããã移æ¤ãã使ãããããã¬ã¼ã ã¯ã¼ã¯ãã¨ããã®ãé£ãããå ¨ä½ãæã£ã¦ãã¾ããã©ã³ã¹ãåãã¦ããã®ãRailsã ããã ã Rubyãããå®è¡æã®æè»æ§ã«æ¬ ãããã®è¨èªã«ã¯Rubyãããããåå®å ¨æ§ããããããããªãããã®è¨èªã§ã¯æ¨æºçãªORãããã¼ãActiveRecordã¨ç°ãªããã¶ã¤ã³ãããããªãããããªãã°ãããããRailsã¨ã¯éããã¶ã¤ã³ãåãã¦ããã¯ãã ã ããã«ãé¢ããã ãRailsãgoã§æ¸ãã¾ããããRailsãPHPã§æ¸ãã¾ãããã¨ããé¡ã®ãã¶ã¤ã³ã«ã¯ãããããããããã
Rubyã®active_recordã©ã¤ãã©ãªãã¾ãå¤ãã®ãã©ãã¯ã¼ãæã¤ã ãããæãåºãã¦æ¬²ããã®ã¯ãããããã® PofEAA ã§ã¯Active Recordã®é©ç¨é åã¯éå®çã ã¨ããã¦ããããactive_recordã©ã¤ãã©ãªã¯Active Recordãã¿ã¼ã³ããé¥ãã«å¤ãã®ãã®ãæä¾ãã¦ããã¨ãããã¨ã ã active_recordã©ã¤ãã©ãªãããã«ä¾åããRailsãè¤éãªã¢ããªã±ã¼ã·ã§ã³ãæ¸ãã®ã«ã使ããã®ã¯ãããããæ¡å¼µæ©è½ãæ§ã ãªç´°ããé æ ®ãå®ç¾©æ¸ã¿ã®Rakeã¿ã¹ã¯ã®ãé°ã§ããã ããããªããã¦ããã active_recordã«å½±é¿ãåãã¦ActiveRecordãã¿ã¼ã³ãè¤éãªã¢ããªã±ã¼ã·ã§ã³ã«æ¡ç¨ããã®ã¯ç¡è¬ããã¾ãã
ãã¦ãã§ã¯ã©ãããã°è¯ãã£ãã®ã ãããããã®ãã³ããæ¬æ¸ã«è¦ããã¨ãã§ããã ããã æ¬æ¸ã¯Rubyã®ã©ã¤ãã©ãªã¯ä½ãèãã¦ãã¶ã¤ã³ããã¦ããã®ãã解説ãã¦ãããã¾ãã©ã¤ãã©ãªç§»æ¤ã®äºä¾ãè±å¯ã«æä¾ãã¦ããã ãã£ã¦ãä½ãRubyåºæã§ãä½ãã移æ¤ããã¨ãã¯ä½ãèæ ®ããªããã°ãªããªãã®ããå¦ã¶ã®ã«ãã£ã¦ã¤ãã§ããã
ãããGoã®ãã®ã©ã¤ãã©ãªã®ãPHPã®ãã®ãã¬ã¼ã ã¯ã¼ã¯ã®ãPythonã®ãã®ãã¼ã«ã®ä½è ãå®æã«Rubyã®ããæ¹ãæµç¨ããåã«æ¬æ¸ãèªãã§ãã¦ãããããããããã¾ã¨ãã«ä½¿ãã代ç©ã§ãã£ãããã«ã¨æããã«ã¯ããããªãã®ã ã