Effective Ruby ããã£ã¨èªã¿ã¾ããï¼
- ä½è : Peter J.Jones
- åºç社/ã¡ã¼ã«ã¼: ç¿æ³³ç¤¾
- çºå£²æ¥: 2015/01/19
- ã¡ãã£ã¢: Kindleç
- ãã®ååãå«ãããã° (5件) ãè¦ã
èãã¨æã£ã¦æ²¹æãããæ¡å¤éãã£ãâ¦â¦ï¼
ãã£ããããææ³ã¨ãã¦ãRuby ããããã使ããããã«ãªã£ã¦ãã人ãèªãã¨é常ã«åå¼·ã«ãªãæ¬ãã ã¨æãã¾ããã èªãã§ã¦ãã¸ãï¼ãããªãã ï¼ãã¨ããããï¼ãã£ã¦ã¿ããï¼ãã¨ãæãããã¨ãå¤ããé¢ç½ãã£ãã§ãã
ãã ãæ¡å¤éãã¦ãå¯ãåã«èªãã§ããã¹ã¤ã¹ã¤ã¨çç¡ãããããã¦ã¾ããã
ä¼ç¤¾ã§ãç¡ç ã« Effective ãªæ¬ãªãããªãã¨ãè¨ããã¾ããã
ç´ æ´ãããæ¬ã§ãã
æ¬é¡
ãã¦ãå®ã¯ã¿ã¤ãã«ããã¡ãã®è¨äºãããã¯ãªã¾ããã
ãã¤ãé£ã§ã¯ã¤ã¯ã¤åããªããåãã¦ãååã®è¨äºã§ãï¼
ããã¾ã§ããããææ³ãæ¸ãæ°åããªãã£ãã®ã§ãç¨ã ã«ææ³ãæ¸ãã¦ãããã¨æãã¾ãã
建åã¨ãã¦ã¯ãæ¬ãèªãã¹ãï¼ç´ æ´ãããï¼ãã§ãæ¬é³ã¨ãã¦ã¯ã詳細ã¯æ¬ãèªãã§ããï¼æ¸ãã®ãã«ãï¼ãã§ãã
ãã ã人ã«æãããã¬ãã«ã®ç解度ã¨ããã®ã¯é常ã«é«ãç¶æ ã ã£ãæ°ãããã®ã§ããã¯ã1度èªåã®è¨èã¨ãã¦ã¢ã¦ããããããã®ã¯é常ã«éè¦ã ã¨æãã¾ãã
ã¨ããããã§ãã¡ãã£ã¨ææ³æ¸ãã¾ãã
æè§ãªã®ã§å
ã»ã©ã®è¨äºã§è§¦ãããã¦ãªãé
ç®ãé¸ã³ã¾ãï¼
é ç®6 Ruby ãç¶æ¿é層ãã©ã®ããã«çµã¿ç«ã¦ã¦ããããé ã«å ¥ããã
ã¯ã©ã¹ã¡ã½ããã¯ãã®ã¯ã©ã¹ï¼ã¯ã©ã¹ããªãã¸ã§ã¯ãï¼ã«å¯¾ããç¹ç°ã¡ã½ããã¨ãã¦å®ç¾©ããã¦ããã¨ããã®ã¯æåã§ãããå ·ä½çã«ã©ãã«å®ç¾©ããã¦ãã®ãã¯èªãã¾ã§è¬ã§ãããã¨ããããç¹ã«èãããã¨ããªãã£ãã§ãã
ã©ããã Ruby ã§ã¯ãç¹ç°ã¡ã½ãããä½ãéãæé»çã«ç¹ç°ã¯ã©ã¹ãä½æããããããç¶æ¿é層ã®çä¸ã«æ¿å ¥ããããã®ç¹ç°ã¯ã©ã¹ã®ã¡ã½ããã¨ãã¦å®ç¾©ãããããã§ãã å ¨ãç¥ãã¾ããã§ããããã©ãããã¯ã©ã¹ã¡ã½ããï¼ã¯ã©ã¹ã®ç¹ç°ã¡ã½ããï¼ã¯å®ã¯ãã£ããä½æãããç¹ç°ã¯ã©ã¹ã«å®ç¾©ãããããã¦ããããã®ã¯ã©ã¹ã¯ãã£ããç¶æ¿ãã¦ããã¨ãããã¨ã§ãã
ã¾ããã¤ã³ã¯ã«ã¼ãæãç¹ç°ã¯ã©ã¹ãæé»çã«ä½ãããèªåã®ç¶æ¿é¢ä¿ã®ä¸ã«æ¿å ¥ããã¾ãã ãªãã¨ãã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¯ã¼ã«ããè£ã§ã¯ç¶æ¿ã ã£ãã®ã§ãï¼ãªãã¦ãã£ãï¼ï¼
ãã¦ãè¨èã ã¨ãããã«ããã®ã§ããã°ã©ã ãæ¸ãã¾ãã
module Foo : end class Bar : end class Foobar < Bar include Foo def self.foobar_self : end def foobar : end end
éã«ã¯ã©ã¹ã¨ã¢ã¸ã¥ã¼ã«ãå®ç¾©ãã¦ã¿ã¾ããã
ããã§ã¯ç¶æ¿é¢ä¿ãè¦ãã¦ããã¾ãã
# ã¾ãã¯æ®éã« Foobar ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããè¦ã¦ã¿ã¾ã >> Foobar.instance_methods(false) => [:foobar] # ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããæ£ããè¿ã£ã¦ãã¾ãã # 次ã«ãFoobar ã¯ã©ã¹ã®ç¹ç°ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããè¦ã¦ã¿ã¾ã >> Foobar.singleton_class.instance_methods(false) => [:foobar_self] # ãã³ãã«ç¹ç°ã¯ã©ã¹ã«å®ç¾©ããã¦ã¾ãã # Foobar ã®è¦ªã¯ã©ã¹ãè¦ãã¦ã¿ã¾ã >> Foobar.superclass => Bar # æ®éã«è¦ªã¯ã©ã¹ãè¿ã£ã¦ãã¾ãã # 次ã«ç¶æ¿é層ãåºåãã¦ã¿ã¾ã >> Foobar.ancestors => [Foobar, Foo, Bar, Object, Kernel, BasicObject] # ã¤ã³ã¯ã«ã¼ããã¦ãã¢ã¸ã¥ã¼ã«ãåºã¦ããï¼
ã¨ã¾ãããã£ãããããªæãã§ãã
è¤æ°ã¢ã¸ã¥ã¼ã«ãã¤ã³ã¯ã«ã¼ããããæã®ç¶æ¿é¢ä¿ãä¸å¿è¦ã¦ããã¾ãããã
class Foobar < Bar include Moge include Foo def self.foobar_self : end def foobar : end end
ãã®ããã«2ã¤ã¤ã³ã¯ã«ã¼ãããã¨ã
>> Foobar.ancestors => [Foobar, Foo, Moge, Bar, Object, Kernel, BasicObject]
å
ã«ã¤ã³ã¯ã«ã¼ãããã¦ãæ¹ãããé ãç¥å
ã«ãªãã¾ããã
åã«ãèªåã®ç´åã«æ¿å
¥ãããã¨ãããã¨ãã·ã³ãã«ã«ãã¦ããã¨ãããã¨ã§ããã
å ¨ä½çã«ç®ããé±ï¼
é ç®15 ã¯ã©ã¹å¤æ°ãããã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã使ãããã«ããã
ã¯ã©ã¹å¤æ°ã¯ãã³ãã«ãã®ã¯ã©ã¹ããã¤ã¹ã¿ãã£ãã¯ãªå¤ã§ãå®å ¨ã«ä¸æã«å®ã¾ãã¾ãã
ä¾ããã®ã¯ã©ã¹ãç¶æ¿ãã¦ããªãã¸ã§ã¯ãããã§ãããããããã¯åãå¤æ°ãåç §ãããã¨ã«ãªãã¾ãã
ããã°ã©ã ãæ¸ãã¦ã¿ã¾ãã
class Bar @@bar = "bar" def self.bar=(bar) @@bar = bar end def self.bar @@bar end end class Foobar < Bar end class Hoobar < Bar end
ãã¦ãããã§ã¯ç¢ºããã¦ã¿ã¾ãã
# å½ç¶ã©ã¡ãã«ãåãå¤ãå ¥ã£ã¦ãã¾ã >> Foobar.bar => "bar" >> Hoobar.bar => "bar" # ããã§ã¯çæ¹æ¸ãæãã¦ã¿ã¾ã >> Foobar.bar = "foo" => "foo" >> Foobar.bar => "foo" >> Hoobar.bar => "foo" # ãã¡ããå¤ãã£ã¦ãã¾ãã¾ããï¼
ã¨ããã£ãæãã§ãã
ããããåä½ãæå³ãã¦ããå ´åã¯åé¡ãªãã®ã§ãããåºæ¬çã«å¤æ°ã¹ã³ã¼ãããã«ãã¦å¬ãããã¨ã¯ãã¾ããªãã®ã§ãé¿ãããã§ãã ããã¨ãããããå ´é¢ã§ã¯ç¶æ¿ããã¯ã©ã¹ãã¨ã«ããããå¥ã®å¤ãæãããããã¨ãå¤ãæ°ããã¾ãã
ãããªç¹ã¯ãã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã使ãã¾ãããã
ã¯ã©ã¹ããªãã¸ã§ã¯ããªã®ã§ãå½ç¶ã¤ã³ã¹ã¿ã³ã¹å¤æ°ãæã£ã¦ãã¾ãã
æ©é使ã£ã¦ã¿ã¾ãããã
class Bar @bar = "bar" def self.bar=(bar) @bar = bar end def self.bar @bar end end class Foobar < Bar end class Hoobar < Bar end
>> Foobar.bar => nil >> Hoobar.bar => nil
ããï¼ã©ã¡ããããè¦ããªããªãã¾ããã ããããã®ã¯ãã§ãã両ã¯ã©ã¹ã¨ãã«å¥ã®ãªãã¸ã§ã¯ãã§ãããããã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¯å ±æãã¦ããã¾ããã
ããã§çµããã®ãæ°æã¡æªãã®ã§ãã¡ãã£ã¨æ¸ããªããã¦ã¿ã¾ãã
class Bar def self.bar=(bar) @bar = bar end def self.bar @bar end end class Foobar < Bar @bar = "foobar" end class Hoobar < Bar @bar = "hoobar" end
ãã¦ãåããã¦ã¿ã¾ãããã
>> Foobar.bar => "foobar" >> Hoobar.bar => "hoobar"
æå³ããéãã®åä½ã«ãªã£ã¦ãããã¨ãä¿è¨¼åºæ¥ã¾ããã
ã¾ããå°ãéã話ã§ãããä»åã®è¨å®æ¹æ³ã¯ã¯ã©ã¹å®ç¾©ä¸ã«ãã¿ã§æ¸ãã¦ãã£ã¦æ°æã¡æªãã§ããã ãã®ããæ¹ã§ã®åæå¤ã®è¨å®ã¯äºæ ã®å ã«è¦ãã¾ãã
ã¡ãã£ã¨ãã£ãããè¨å®ã§ããããã«ãã¦ã¿ã¾ãã
# è¨å®é ç®ãä¿æããã¯ã©ã¹ class Configuration attr_accessor :bar end class Bar # ç¶æ¿å ã§å¼ã³åºãã¦ãããè¨å®ã¯ã©ã¹ def self.configure configuration = Configuration.new yield configuration @config = configuration.bar @bar = @config.bar end def self.bar=(bar) @bar = bar end def self.bar @bar end end class Foobar < Bar # åæå configure do |config| config.bar = "foobar" end end class Hoobar < Bar # åæå configure do |config| config.bar = "hoobar" end end
ããããã¨ãã¡ãã£ã¨ãã£ãããåã¯ã©ã¹ã®åæå¤ã渡ããã¨ãåºæ¥ã¾ãã
# ã¡ãã£ã¨ã«ãã³è¯ãï¼ configure do |config| config.foo = "foo" config.bar = "bar" end
é話ä¼é¡ã
åºæ¬çã«ã¯ã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã使ãã®ãåã ã¨æãã¾ãã
第8ç« ã¡ã¢ãªç®¡çã¨ããã©ã¼ãã³ã¹
ããã ãç« ã§ã¨ãããã¾ããã
ãããã話ãè¼ã£ã¦ãã®ãåãè¯ããªãã¨æã£ãã®ã§ãã£ããç« ã§ã¨ãããã¾ããã ã¬ãã¼ã¸ã³ã¬ã¯ã¿ã®ãã¥ã¼ãã³ã°ãããããã¡ã¤ã«ãåãæ¹æ³ãªã©ã«ã¤ãã¦ä¹ã£ã¦ãã¾ãã
ä¾ãã°ãé ç®46 Ruby ãããã¡ã¤ãªã³ã°ãã¼ã«ã使ãããã§ã¯ã
- ãããã¡ã¤ãªã³ã°ãã¼ã«ã使ã£ã¦ããããã©ã¼ãã³ã¹ã»ãã¥ã¼ãã³ã°ããã¾ããã
ã¨ãã£ããã¨ãæ¸ãã¦ããã¾ãã
ã¾ãããã㯠Effective Ruby ã¨ã¯é¢ä¿ããã¾ããããRuby ã®ã¬ãã¼ã¸ã³ã¬ã¯ã¿ã®ä»çµã¿ã«ã¤ãã¦ã¯ä»¥ä¸ã®è¨äº*1ãå³ããããé常ã«ããããããã£ãã§ãã
Ruby 㨠Python ã®ã¬ãã¼ã¸ã³ã¬ã¯ã¿ã®éãã«ã¤ãã¦æ¸ãã¦ããã¾ãã
ãã®ç« ã¨ã¯ç¹ã«é¢ä¿ãªãã§ãããããã©ã¼ãã³ã¹é¢ä¿ã§æãåºããè¨äºãããä¸ã¤ç´¹ä»ãã¾ãã
Ruby ã«ãã並åã»ä¸¦è¡ããã°ã©ãã³ã°ã«é¢ããè¨äºã§ãã
ã©ã¡ããè±èªã§ãããèªãã§ã¦é常ã«é¢ç½ãã£ãã®ã§ãªã¹ã¹ã¡ã§ãï¼
追è¨
POSTD ã« Visualizing Garbage Collection in Ruby and Python ã®æ¥æ¬èªè¨³ãæ²è¼ããã¦ãã¾ããï¼
ã¾ã¨ã
é常ã«è¯ãæ¬ã ã¨æãã¾ãã®ã§ã1度ç®ãéãã¦ã¿ããã¨ããªã¹ã¹ã¡ãã¾ãï¼
次ã®æ¬
次ã«èªã¿ãããªã¨æã£ã¦ã Ruby é¢ä¿ã®æ¬ã¯ãã¡ãã§ãã
ãã£ã¨éåã§ããã¤ãã¤ã§ããä¼ç¤¾ã§è²·ã£ã¦ãããã¾ããã
ãªãã¡ã¯ã¿ãªã³ã°:Rubyã¨ãã£ã·ã§ã³
- ä½è : Jay Fields,Shane Harvie,Martin Fowler,Kent Beck,é·å°¾é«å¼
- åºç社/ã¡ã¼ã«ã¼: ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹
- çºå£²æ¥: 2010/02/27
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 9人 ã¯ãªãã¯: 321å
- ãã®ååãå«ãããã° (49件) ãè¦ã
Ruby 以å¤ã®æ¬ã§ç´è¿èªããã¨æã£ã¦ãæ¬ãã¤ãã§ã«ç´¹ä»ãã¦ããã¨ã以ä¸ã®2åã§ãã
- ä½è : 大西泰æ,ãã¼ã«ã»ãã¯ãã¤
- åºç社/ã¡ã¼ã«ã¼: ãã¬ã»
- çºå£²æ¥: 2011/09/09
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 12人 ã¯ãªãã¯: 68å
- ãã®ååãå«ãããã° (50件) ãè¦ã
ãã¹ã¿ãªã³ã°TCP/IP å ¥éç·¨ 第5ç
- ä½è : 竹ä¸éå²,æå±±å ¬ä¿,èäºé,è ç°å¹¸é
- åºç社/ã¡ã¼ã«ã¼: ãªã¼ã 社
- çºå£²æ¥: 2012/02/25
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 4人 ã¯ãªãã¯: 34å
- ãã®ååãå«ãããã° (37件) ãè¦ã
ããã¦èªæ¸ä¼ã§ã¡ããã¡ããèªã¿é²ãã¦ã Haskell 並å並è¡æ¬ãã¯ããã¿â¦â¦ãã£ã±ãããï¼
ãã£ããªã¼ãã¼ã§æ»ãªãªãããã«ããã¾ãæãã«ãããããèªã¿é²ãã¦ããã¾ãã
ã¨ããããã¯è±èªã®æ¬ã¨ãã¹ã¿ãªã³ã° TCP/IP å ¥éç·¨ãèªãã§ã¿ã¾ã¼ãï¼
æææ¥
ä»æ¥ã¯æ©å¯ããã£ã¦æ±ºããã®ã«â¦â¦ï¼
*1:追è¨ï¼æ¥æ¬èªè¨³ãPOSTDã«æ²è¼ããã¦ãã¾ããï¼