freezeã§ããªããæ¢åã®å®æ°ãã£ã¦ä½ï¼ - Effective Ruby
ãEffective Rubyããèªãã§ã®ã¡ã¢ãååã¯ãã¡ãã
ä»æ¥ã¯2ç« ã®é ç®10ã¾ã§èªã¿ãããã¾ããã1ç« ã®ç¶ãã復ç¿ãã¾ãã
é ç®4 å®æ°ããã¥ã¼ã¿ãã«ãªãã¨ã«æ³¨æããã
Rubyã§ã¯å®æ°ã¯æ¸ãæããããå¤ãªã®ã§ãæ¸ãæãããã¦å°ãå¤ã¯freezeãããã¨ãã話ã
é åã®å®æ°ã使ãå ´åã¯ãé åèªä½ã¨ãé åã®è¦ç´ ã両æ¹freezeããå¿ è¦ãããã
çåç¹
p.11ã®æ¬¡ã®æç« ããããåãããªãã£ãã
å®æ°ãããªã¼ãºããã°ãç®ç«ããã追跡ãã«ãããã°ãä¾å¤ã«å¤ãããã¨ãã§ãããããã¯ãæããã«å¤§ããªãã¨ã ãããããããã§ã¯ã¾ã ååã§ã¯ãªããå®æ°ãåç §ãããªãã¸ã§ã¯ããããªã¼ãºãã¦ããæ¢åã®å®æ°ã«æ°ããå¤ãä»£å ¥ããã°ãåé¡ãèµ·ããã
ä¸ã®æç« ã®ãæ¢åã®å®æ°ããä½ãæå³ãã¦ããã®ããåãããªããæ¢åï¼
ãã®ãã ãã§ã¯ã次ã®ãããªãµã³ãã«ã³ã¼ãã§ããæ¢åã®å®æ°ãã§ããã¨ããã®TIMEOUTã¨ããå¤ã«å¯¾ãã¦å¤ãä»£å ¥ã§ãã¦ãã¾ããã¨ã示ãããã
irb(main):001:0> TIMEOUT=5 => 5 irb(main):002:0> TIMEOUT += 5 (irb):2: warning: already initialized constant TIMEOUT (irb):1: warning: previous definition of TIMEOUT was here => 10
ãããã«å®æ°TIMEOUTèªä½ãfreezeããããå¤ãä»£å ¥ã§ãã¦ãã¾ãã
irb(main):003:0> TIMEOUT.freeze => 10 irb(main):004:0> TIMEOUT += 5 (irb):4: warning: already initialized constant TIMEOUT (irb):2: warning: previous definition of TIMEOUT was here => 15
å®æ°TIMEOUTã¯ç´æ¥freezeã§ããªãï¼ãã¦ãæå³ããªãï¼ï¼ã¨ãããã¨ã¯åããã
æ¬æã§ã¯ãmoduleã®ä¸ã«TIMEOUTãå®ç¾©ãã¦ãmoduleèªä½ãfreezeããã¨ãã対å¦æ³ãè¿°ã¹ããã¦ããã
é ç®5 å®è¡æã®è¦åã«æ³¨æããã
Rubyã¯ãæ§æ解æãã§ã¼ãºï¼æ¬æã§ã¯ã³ã³ãã¤ã«æã¨å¼ãã§ããï¼ã¨å®è¡ãã§ã¼ãºã®2ã¤ã§ã³ã¼ããæä½ãããå¦çç³»ã®ãªãã·ã§ã³ãæ´»ç¨ããã¨ãããããã®ãã§ã¼ãºã§å¥ã®ç¨®é¡ã®è¦åã表示ã§ããã
- ã³ã³ãã¤ã«æã®è¦åã®åºãæ¹
- rubyã¤ã³ã¿ããªã¿å®è¡æã«-wãªãã·ã§ã³ãã¤ãã
- ãããã¯ãRUBYOPTç°å¢å¤æ°ã«-wãè¨å®ãã
- å®è¡æã®è¦åã®åºãæ¹
- ããã°ã©ã ã®ä¸ã§$VERBOSEã°ãã¼ãã«å¤æ°ã«trueãè¨å®ããï¼è¦åãç¡å¹ã«ãããæã¯nilãè¨å®ããï¼
-wãªãã·ã§ã³ãã¤ãããã¨ã¨ãVERBOSEå¤æ°ã使ããã¨ã¯ãæä»ã§ã¯ãªãã両æ¹ããã¨ããã®ãçè ã®ä¸»å¼µã
è¦åãæ´»ç¨ãã¦ã³ã¼ããä¿®æ£ããããRubyã«ã³ã¼ãã®æå³ãæ¨æ¸¬ãããã®ã¯ãããããã¨ãã話ã ã£ãã
ä»æ¥ã¯ããã¾ã§ã第1ç« ã¯çµäºã
- ä½è : Peter J. Jones,arton,é·å°¾é«å¼
- åºç社/ã¡ã¼ã«ã¼: ç¿æ³³ç¤¾
- çºå£²æ¥: 2015/01/09
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (13件) ãè¦ã