From: James Edward Gray II Date: 2005-10-01T00:28:35+09:00 Subject: Re: Operator Overloading << On Sep 30, 2005, at 9:56 AM, Matt Hulse wrote: > Are delegates common to all OO languages? I don't remember learning > about them in my C++ class. Delegation is a design pattern and in that sense, yes, it's common to most languages: http://en.wikipedia.org/wiki/Delegation_%28programming%29 In Ruby, we have two standard libraries that cover delegation. I just finished documenting them and am trying to get them up on ruby- doc.org, but until then, here's some sample code from the docs of delegate.rb: # # The primary interface to this library. Use to setup delegation when defining # your class. # # class MyClass < DelegateClass( ClassToDelegateTo ) # Step 1 # def initiaize # super(obj_of_ClassToDelegateTo) # Step 2 # end # end # and # # === DelegateClass() # # Here's a sample of use from tempfile.rb. # # A _Tempfile_ object is really just a _File_ object with a few special rules # about storage location and/or when the File should be deleted. That makes for # an almost textbook perfect example of how to use delegation. # # class Tempfile < DelegateClass(File) # # constant and class member data initialization... # # def initialize(basename, tmpdir=Dir::tmpdir) # # build up file path/name in var tmpname... # # @tmpfile = File.open(tmpname, File::RDWR|File::CREAT| File::EXCL, 0600) # # # ... # # super(@tmpfile) # # # below this point, all methods of File are supported... # end # # # ... # end # Hope that helps. James Edward Gray II