Re:"DCI" in Ruby is completely broken
by technoweenie on Wednesday January 02, 2013 @12:39PM
(#4997884)
I was curious what Tony's graph would look like using a SimpleDelegator as he suggested.
RUBY:
[ Parent
| on HN ]
Which is pretty much what you'd expect... making two objects instead of one cuts the speed approximately in half.
Re:"DCI" in Ruby is completely broken
by urbanautomaton on Wednesday January 02, 2013 @01:33PM
(#4998289)
I took a stab at separating out the method dispatch costs from the cost of the #extend call here https://gist.github.com/4436640. I also tried making a call against an unmodified instance of a completely different class to demonstrate that the global method cache is indeed flushed in MRI by doing a runtime #extend on any object instance.
Subtracting the results of different runs like this is pretty questionable, though (the errors accumulate), so the above is to be taken with a pinch of salt.
the example in the op was somewhat misleading in that he was extending the object within its initialize method. i think you'd more often want to do a per-object extend dynamically at runtime to simulate something like smalltalk's #become, where the object would be modifying its capabilities and 'type' based on some external input conditions.