Webアプリエンジニア養成読本 Advent Calendar 2014 - Qiita ã®21æ¥ç®ã§ããã¬ãã§æ¸ããã¨ããªããªã£ã¦ãã¾ããï¼æ縮ã§ãã
- ä½è : åç°è£ä»,ç³ç°çµ¢ä¸(uzulla),ããããã¾ãã®ã,æè¤ç¥ä¸é
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2014/03/11
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (5件) ãè¦ã
æ¬ä¼¼å¤æ°ãã¡
æ¬æ¸ã§ã¯ãã¾ã触ãã¦ãã¾ããã§ããããRubyã§ã¯æ¬ä¼¼å¤æ°ã¨å¼ã°ãããå¤æ°ã®ãããªå¤ãããã¤ãåå¨ãã¾ããä¾ãã°ãtrue
ãfalse
ãããã«è©²å½ãã¾ãã
ãã以å¤ã§é¢ç½ããã®ã¨ãã¦ã__FILE__
ã__LINE__
çãããã¾ãããããã¯å®è¡ããæç¹ã§ã®ãã¡ã¤ã«ã®ãã¹ãè¡æ°ãåå¾ãããã¨ãã§ãã¾ãã
ã¡ãªã¿ã«ãRuby 2.0.0ããã¯__dir__
ã¨ããã¡ã½ããï¼ããã¯ç¹æ®å¤æ°ã§ã¯ãªãã®ã ã£ãï¼ã追å ããã¦ãã¦ãããã使ã㨠File.dirname(__FILE__)
ç¸å½â¦â¦ã¤ã¾ãã該å½ã®ãã¡ã¤ã«ãæ ¼ç´ããã¦ãããã£ã¬ã¯ããªé¨åãåå¾ã§ãã¾ãã
ãããªæãã®ã³ã¼ãã§è©¦ãã¦ã¿ã¾ãããã
cat hoge.rb puts "start:hoge" puts __FILE__ puts __LINE__ puts __dir__ puts "end:hoge"
ãããå®è¡ãã¦ã¿ãã¨
$ ruby hoge.rb start:hoge hoge.rb 3 /private/tmp end:hoge
ãããªæãã§åå¾ã§ãã¾ãã
詳ãã㯠変数と定数 ãè¦ã¦ãã ããã
ãã®ä»ã«ãã使ããã®
æ¬ä¼¼å¤æ°ã®ãããªãããã§ã¯ããã¾ããããä¾ãã°ã³ãã³ãã©ã¤ã³å¼æ°ãæ±ãããã®å¤ã¨ãã¦ãARGVãARGFãããã¾ãã
ARGV.each do |arg| puts arg end
ãããå¼æ°ä»ãã§å®è¡ããã¨ãããªæãã«ãªãã¾ãã
$ ruby sample.rb foo bar baz foo bar baz
ARGFã使ãã¨ãå¼æ°ã®å¤ããã¡ã¤ã«ãã¹ã¨ã¿ãªãã¦ãå 容ãèªã¿è¾¼ããã¨ãã§ãã¾ãã詳ãã㯠constant Object::ARGV 㨠object ARGF ãåç §ãã¦ãã ããã
ãããã¸ãã®ãªãã¸ã§ã¯ããªã©ãå©ç¨ã§ããããã«ãªãã¨ãã¡ãã£ã¨ããã³ãã³ãã©ã¤ã³ãã¼ã«ãä½ãã¨ãã«å½¹ã«ç«ã¡ã¾ããã
ãã¾ã
Rubyã§ã¯puts
çã®ã¬ã·ã¼ããæå®ããªãã¡ã½ããã¯ããããKernelã«å®ç¾©ããã¦ãããã®ã§ãã module Kernel ããããè¦ãã¨ãä¾ãã° exit
ã sleep
çã®ã¡ã½ãããå®ç¾©ããã¦ããã®ããããã¾ããã¡ãã£ã¨ããã³ã¼ããæ¸ãã¨ãã«ç¥ã£ã¦ããã¨ä¾¿å©ãªã¤ã¼ããããã®ã§ããããã¸ãã®ã¡ã½ããã»ç¹æ®å¤æ°ã¯æãã¦ããã¨è¯ãã§ãããã
æ¸ããªãã¦ã¯ãããªã宣ä¼
ä»åã®ã¨ã³ããªã§æ¸ãããããªãã¨ã¯æ¸ãã¦ãã¾ããããæ¸åºãªã©ã§è¦ã¤ããããã²ç«ã¡èªã¿ã§ããã¦ã¿ã¦ãããããã°è³¼å ¥ãã¦ã¿ã¦ãã ãããã
- ä½è : åç°è£ä»,ç³ç°çµ¢ä¸(uzulla),ããããã¾ãã®ã,æè¤ç¥ä¸é
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2014/03/11
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (5件) ãè¦ã
enjoy!