æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.1ï¼»CHAPTER3 ã»ãã¨ã«ç¡è½ï¼½
è¨äºã®æ¦è¦
ãæããããã°ã©ã ãã®ï¼»CHAPTER3 ã»ãã¨ã«ç¡è½ï¼½ã§ä½æãããã£ãããããããã°ã©ã ãããã®ã¾ã¾ã³ã³ã½ã¼ã«ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦ãMacã®ã¿ã¼ããã«ã§åããã¾ãã
Webã¢ããªã«ããä½æ¥ã«åãæããåã«ãã¾ãã¯ãæããããã°ã©ã ãã®åºæ¬æ§é ãå¦ã³ã¾ãã
注ï¼ãã®è¨äºã§ã¯ã¾ã ãWebã¢ããªã¨å¼ã¹ã代ç©ã¯åºã¦ãã¾ããã
ç®æ¬¡
- è¨äºã®æ¦è¦
- ç®æ¬¡
- éçºç°å¢
- protoã¨ä¼è©±ãã
- protoã®å¿çã®ç¨®é¡ãå¢ãã
- åèæ¸ç±
- é¢é£è¨äº
éçºç°å¢
- OSX 10.11.2 El Capitan
- ããã¹ãã¨ãã£ã¿ï¼ MacVim
- ã¿ã¼ããã«ã¨ãã¥ã¬ã¼ã¿ï¼ Macã¿ã¼ããã«
- ã·ã§ã«ï¼ zsh
- ããã±ã¼ã¸ããã¼ã¸ã£ï¼ Homebrew - Ruby 2.0.0p645
- ãã¼ã¸ã§ã³ããã¼ã¸ã£ï¼ rbenv
åèè¨äº
Rubyã®éçºç°å¢æ§ç¯ã¯ããã¡ãã®è¨äºãåèã«ããã¦ããã ãã¾ããã
protoã¨ä¼è©±ãã
å ¥åããæååã«å¯¾ãããã£ã¦ãªã«?ãã追å ããå¿çãè¿ããã£ããããããä½æãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªã®æ§æ
~/programinlove
|- proto.rb // åºæ¬çãªãã£ãããããããã°ã©ã ã®å
¨ã¦ãè©°ã¾ã£ãã¡ã¤ã³ãã¡ã¤ã«
ã½ã¼ã¹ã³ã¼ã
ãµã³ãã«ããã°ã©ã ã®ã¾ã¾ã ã¨ã¨ã©ã¼ãåºãã®ã§ããã¸ãã¯ã³ã¡ã³ããåé¤ãã¾ããã
ãµã³ãã«ããã°ã©ã ã§ã¯ãRuby1.8ã§æåã³ã¼ãã«ã·ããJISã使ç¨ãã¦ãããã#! ruby -Ks
ãå¿
è¦ãããã®ã§ãããRuby2.0ã§ãã®è¨è¿°ãããã¨ã·ã³ã¿ãã¯ã¹ã¨ã©ã¼ã«ãªãããã§ãã
ã¾ããRuby2.0ã§ã¯ããã©ã«ãã§UTF-8ãé©ç¨ããããããUTF-8ã®ç°å¢ã§ã¯ãã¸ãã¯ã³ã¡ã³ããä¸è¦ãããã§ãã
ã³ã¼ãã¯ã
//proto.rb #! ruby -Ks class Responder
ã®é¨åã
//proto.rb class Responder
ã«å¤æ´ãã¦ã[chapter3-3]ã®ã¿ã°ãä»ãã¦ç½®ãã¦ã¾ãã
å®è¡çµæ
ãã®proto.rb
ãã¿ã¼ããã«ã§åããã¨ãä¼è©±æ°åã楽ããã¾ãã
~/programinlove $ruby proto.rb Unmo System prototype : proto > ããã«ã¡ã proto:What> ããã«ã¡ãã£ã¦ãªã«ï¼ > ãããã¤ã§ãã proto:What> ãããã¤ã§ããã£ã¦ãªã«ï¼ > Huh? proto:What> Huh?ã£ã¦ãªã«ï¼ > (#^Ï^)
protoã®å¿çã®ç¨®é¡ãå¢ãã
å ¥åããæååã¨ã¯é¢ä¿ç¡ããç¨æãããï¼ç¨®ã®å¿çããï¼ã¤ãã©ã³ãã ã«è¿ããã£ããããããä½æãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªã®æ§æ
~/programinlove
|- proto.rb // å
¥åã¨åºåãããã ãã®ã¡ã¤ã³ãã¡ã¤ã«
|- unmo.rb // ãã£ããããããªãã¸ã§ã¯ãã®ã¢ãã«
|- responder.rb // å¿çãªãã¸ã§ã¯ãã®ã¢ãã«
ã½ã¼ã¹ã³ã¼ã
ãã¯ããµã³ãã«ããã°ã©ã ã®ã¾ã¾ã§ã¯åããªãã£ãã®ã§ããã¸ãã¯ã³ã¡ã³ãã®åé¤ã®ä»ã«ãrequrire
ãrequire_relative
ã¸å¤æ´ãã¾ããã
Ruby1.9.2ãããã«ã¬ã³ããã£ã¬ã¯ããªãrequire
ã®ãã¼ããã¹ããé¤ãããããã§ãä»åã®ããã°ã©ã ã§ã¯
ãã¡ã¤ã«æ°ãå¤ããªãããrequire_relative
ã使ã£ã¦åããã¾ããã
ã³ã¼ãã¯ã
//proto.rb #! ruby -Ks require 'unmo' def prompt(unmo)
ã®é¨åã
//proto.rb require_relative 'unmo' def prompt(unmo)
ã«ã
//unmo.rb require 'responder' class Unmo
ã®é¨åã
//unmo.rb require_relative 'responder' class Unmo
ã«å¤æ´ãã¦ã[chapter3-4]ã®ã¿ã°ãä»ãã¦ç½®ãã¦ã¾ãã
å®è¡çµæ
ãã®proto.rb
ãã¿ã¼ããã«ã§åããã¨ãåã¿åããªãä¼è©±ã楽ããã¾ãã
~/programinlove $ruby proto.rb Unmo System prototype : proto > ããã«ã¡ã proto:Random> ãã®ã10åã²ãã£ã > ããã¯è¯ãã£ãã§ãã proto:Random> ãã®ã10åã²ãã£ã > ãããªã«å¬ããã£ããã§ããï¼ proto:Random> ãã®ã10åã²ãã£ã > oh proto:Random> ä»æ¥ã¯ãããã > ããã§ãã proto:Random> ãã§ã³ãã¹ãã > ã ã¡ãã£ã£ã¨ proto:Random> ä»æ¥ã¯ãããã >
åèæ¸ç±
é¢é£è¨äº
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.0ï¼»ã¯ããã«ï¼½
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.2ï¼»CHAPTER4 ããããã®GUIï¼½â
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.3ï¼»CHAPTER4 ããããã®GUIï¼½â¡
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.4ï¼»CHAPTER4 ããããã®GUIï¼½â¢
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.5ï¼»CHAPTER5 è¾æ¸ãçæã«ï¼½
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.6ï¼»CHAPTER6 ææ
ã³ã³ããã¼ã«ã®éè¡å¸«ï¼½â
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.7ï¼»CHAPTER6 ææ
ã³ã³ããã¼ã«ã®éè¡å¸«ï¼½â¡
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.8ï¼»CHAPTER7 å¦ç¿ã®ã¹ã¹ã¡ï¼½â
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.9ï¼»CHAPTER7 å¦ç¿ã®ã¹ã¹ã¡ï¼½â¡
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.10ï¼»CHAPTER7 å¦ç¿ã®ã¹ã¹ã¡ï¼½â¢
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.11ï¼»CHAPTER8 æç« ãä½ãåºãï¼½
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.12ï¼»CHAPTER9 ããã£ããããã¯ã¼ã¯ã«ã¤ãªããï¼½
- æããããã°ã©ã ãSinatraã§Webã¢ããªã«ããPart.13ï¼»ãããã«ï¼½
*1:ä¸è¿°ã®ã½ã¼ã¹ã³ã¼ããå®è¡ãã¦ãé¡æåã¯åºã¾ãã