DelegateClass vs. Extending

B

Brian Doyle

I was looking at DelegateClass example:

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

and was wondering what is the advantage of doing this and not just
extending the File class? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top