chainable

PHP OOP: Chainable objects?

Hi everybody, I have tried to find a good introduction on chainable OOP objects in PHP, but without any good result yet. How can something like this be done? $this->className->add('1','value'); $this->className->type('string'); $this->classname->doStuff(); Or even: $this->className->add('1','value')->type('string')->doStuff(); Tha...

Ruby chainable method / array

How do I implement the '<<' to have the same behavior when used as a chainable method? class Test attr_accessor :internal_array def initialize @internal_array = [] end def <<(item) @internal_array << :a @internal_array << item end end t = Test.new t << 1 t << 2 t << 3 #t.internal_array => [:a, 1, :a, 2, :a, 3] p...