Classbox ã®ã¡ã½ããæ¢ç´¢ã«ã¼ã«
Rubyä¼è°ã§é£ã³åºã Ruby 2.0 ã®äºå®ãç®çã« Smalltalk ã®ç¹ã« Squeak ã§åãã¦å®è£
ã試ããããããã®æ©è½ãï¼ã¤ããã£ã¦ãSqueakãã¡ã³ã¨ãã¦ã¯å®ã«ï½ï½ï½ï½ã§ãããå人çã«ããæå¹Rubyä¼è°02ã§ã® こちら ãå£ããåºä»»ãã«ãªããã«æ¸ã¿ããã§ããã£ããªã¼ã¨ã²ã¨å®å¿ãï½
ã§ãé¢é£ãã¦ãããªã¤ã¶ãããè¦ãããã®ã§ãSqueak ã® Classbox ã®å®è£
ãä¹
ãã¶ãã«å¼ã£å¼µãåºãã¦èª¿ã¹ã¦ã¿ã¾ããã
ããï¼ æ¬å®¶ã®classboxã®ã¡ã½ããæ¢ç´¢ã«ã¼ã«ããã¾ãã¡ããããªããéçã¹ã³ã¼ãã§ã®è§£æ¶ãããªããã ãããããåçã¹ã³ã¼ãã£ã¦ãã¨ï¼
Twitter / yukihiro_matz
è«æã¯ããã¤ãããã¾ããããã¡ããæ¯è¼çãããããã¨ã
- Scoped and Dynamic Aspects with Classboxes [PDF]
Classboxï¼å人çã«ã¯ãTraits åæ§ãå°æåã®åæ°å½¢ã¯ã¨ã³ãã£ãã£ã表ãããæ©æ§ã¨ãã¦ã¯å¤§æåã®è¤æ°å½¢ã§ Classboxes ã使ãæ¹ã好ã¿ã§ããâï¼ã®åä½ç¢ºèªã®ããã« Squeak Smalltalk ã§çµã¾ããã³ã¼ãã¯ãç¾å¨ã§ã試ä½æ®µéã®ãã®ãªãããSqueakMap ã SqueakSource ãªã©ã®ããã±ã¼ã¸ã·ã¹ãã çµç±ããå
¥æå¯è½ã§ãããã ããããã®ããã±ã¼ã¸ã·ã¹ãã ã«ãªãã¿ã®ãªãå ´åã¯ãéçºãé²ãããã¦ãã 2004å¹´ããã«é
å¸ããã¦ãã classboz.zip ãå
¥æãã¦ä½¿ç¨ããã®ãããã§ããããããã§ããããç¨åº¦æ
å ±ãå¾ããã¨æã£ãããSqueak Smalltalk ç°å¢ã®ä½¿ãæ¹ããããªãã«ç¥ã£ã¦ããå¿
è¦ã¯ããã¾ããâ¦ã^^;
classbox.zip ãå±éãããã¹ãOS åãï¼WinãMacãLinuxï¼ã®ä»®æ³ãã·ã³ãå¥é ftp.squeak.org ããå
¥æãåããã£ã¬ã¯ããªã«å
¥ããclassbox.image ããã®ä»®æ³ãã·ã³ã«ã«ããããã¤ã³ããã®ãç°¡åã§ããããé
å¸ããã¦ãã classbox.image ã¯ãSqueak3.7 å½æã®ãã®ãªã®ã§ãä»®æ³ãã·ã³ããã®ãã¼ã¸ã§ã³ã«åããã¾ãã
ã¡ã½ããæ¢ç´¢ã®ã«ã¼ã«ã«ã¤ãã¦ã¯ããã¹ãåãã«æ¸ããã LocalRebindingTests ã® #testLocalRebinding2 ã #testLocalRebindingDiamond1 ããããåèã«ãªãããã«æãã¾ãã
LocalRebindingTests >> testLocalRebinding2 "self run: #testLocalRebinding2" | cx1 cx2 | self switchToLocalRebinding. cx1 := self createClassboxNamed: #CB1. cx2 := self createClassboxNamed: #CB2. cx1 import: #Object from: system. cx1 createClassNamed: #A. cx1 createClassNamed: #B. cx1 createClassNamed: #C. cx1 createClassNamed: #D. cx1 addMethod: 'foo ^ 10' for: #A. cx1 addMethod: 'bar ^ self foo ' for: #A. cx1 addMethod: 'foo ^ A new foo' for: #B. cx1 addMethod: 'foo ^ B new foo' for: #C. cx1 addMethod: 'foo ^ C new foo' for: #D. cx2 import: #A from: cx1. cx2 import: #D from: cx1. cx2 addMethod: 'foo ^ 20' for: #A. self assert: (cx1 evaluate: 'A new bar') = 10. self assert: (cx1 evaluate: 'D new foo') = 10. self assert: (cx2 evaluate: 'A new bar') = 20. self assert: (cx2 evaluate: 'D new foo') = 20.
LocalRebindingTests >> testLocalRebindingDiamond1 | cx1 cx2 cx3 cx4 | cx1 := self createClassboxNamed: #CX1. cx2 := self createClassboxNamed: #CX2. cx3 := self createClassboxNamed: #CX3. cx4 := self createClassboxNamed: #CX4. cx1 import: #Object from: system. cx1 createClassNamed: #A. cx1 addMethod: 'foo ^ 1' for: #A. cx1 addMethod: 'bar ^ self foo' for: #A. cx2 import: #A from: cx1. cx2 addMethod: 'foo ^2' for: #A. cx2 createClassNamed: #B superclass: #A. cx3 import: #A from: cx1. cx3 addMethod: 'foo ^3' for: #A. cx3 createClassNamed: #C superclass: #A. cx4 import: #B from: cx2. cx4 import: #C from: cx3. self assert: (cx4 evaluate: 'B new bar') = 2. self assert: (cx4 evaluate: 'C new bar') = 3. cx4 import: #A from: cx1. self assert: (cx4 evaluate: 'B new bar') = 1. self assert: (cx4 evaluate: 'C new bar') = 1.
ãªã«ã¶ãæ§æãç¨æããã¦ããããæç¶ãçã§éæ®ã£ããã®ã§ããã£ã¦ãããã¨ãç¡çç¢ç Ruby ã£ã½ãæ¸ãä¸ãã¦ã¿ãã®ã以ä¸ã§ãã
#testLocalRebinding2 classbox CB1 import Object class A def foo; 10 end def bar; foo end end class B def foo; A.new.foo end end class C def foo; B.new.foo end end class D def foo; C.new.foo end end end classbox CB2 import A, D from CB1 class A def foo; 20 end end end assert_equal( CB1.classbox_eval{ A.new.bar }, 10 ) assert_equal( CB1.classbox_eval{ D.new.foo }, 10 ) assert_equal( CB2.classbox_eval{ A.new.bar }, 20 ) assert_equal( CB2.classbox_eval{ D.new.foo }, 20 )
#testLocalRebindingDiamond1 classbox CX1 import Object class A def foo; 1 end def bar; foo end end end classbox CX2 import A form CX1 class A def foo; 2 end end class B < A; end end classbox CX3 import A form CX1 class A def foo; 3 end end class C < A; end end classbox CX4 import B from CX2 import C from CX3 end assert_equal( CX4.classbox_eval{ B.new.bar }, 2 ) assert_equal( CX4.classbox_eval{ C.new.bar }, 3 ) classbox CX4; import A from CX1 end assert_equal( CX4.classbox_eval{ B.new.bar }, 1 ) assert_equal( CX4.classbox_eval{ C.new.bar }, 1 )
ãªã«ãã®åèã«ãªãã°ããããã§ãã
ä½è«ã¨ãã¦ããããæ¸ãã¦ããã¨ãã«æ°ãã¤ããã®ã§ãããSqueak ä¸ã§ã®å®è£ ã¯ããã¼ã¸ã§ã³150 ãå¢ã«ãï¼å人çã«ã¯æ°ã«å ¥ã£ã¦ããâï¼åçãªæ§æ ¼ããã£ããã¨ããè½ã¨ããã¦ãã¾ã£ãããããã¨ãè¦ã¤ãã¾ããã
ãã¨ãã°ã以åã¯ã«ã¬ã³ãã¹ã¬ãããã³ã³ããã¹ãã¨ã㦠classbox ãæã¤ãã¨ãã§ãã¦ããããé©å®åãæ¿ãããã¨ã§æåãå¤åããããã¨ãå¯è½ã ã£ãã¯ããªã®ã§ããã150 ããå¾ã§ã¯ããããæ©æ§ã¯å¤±ããã¦ãã¦ããã£ã±ãã¯ã©ã¹ãæã£ã¦ãããã©ã® classbox ããã¤ã³ãã¼ããããããã¨ããæ å ±ãå ã«éçã«è§£æ±ºãããæ©æ§ã«ãªã£ã¦ãã¾ããå人çã«ã¯ã¡ãã£ã¨ãã£ããã§ãããä½ãããå°é£ããã£ããããããã¯ãä»ã®è¨èªã§å®è£ ãããããã¨ãªããä»æ§ã«è½ã¡çããã®ããããã¾ãããã