<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Jonathon,<div class=""><br class=""></div><div class="">Looks like it’s Ruby all the way down:</div><div class=""><br class=""></div><div class=""> <a href="http://ruby-doc.org/stdlib-2.2.2/libdoc/delegate/rdoc/Object.html" class="">http://ruby-doc.org/stdlib-2.2.2/libdoc/delegate/rdoc/Object.html</a></div><div class=""><br class=""></div><div class="">The example is a little hard to read at a glance, but this is a method to allow composition instead of inheritance. One might rewrite the code something like this to make it more obvious what’s being attempted in this case (with apologies for quick hackiness and glossed-over subtleties):</div><div class=""><br class=""></div><div class=""> class Tempfile</div><div class=""> def initialize basename, temp_dir = '/tmp'</div><div class=""> file_name = [ basename, rand(1_000_000_000), Time.now.to_f ].join('-')</div><div class=""> file_path = File.join temp_dir, file_name</div><div class=""> @file = File.open file_path, ...</div><div class=""> end</div><div class=""><br class=""></div><div class=""> def method_missing name, *args</div><div class=""> @file.send name, *args</div><div class=""> end</div><div class=""><br class=""></div><div class=""> def respond_to? name</div><div class=""> @file.respond_to? name</div><div class=""> end</div><div class=""> end</div><div class=""><br class=""></div><div class="">The resulting class will support the same API and behaviour as the class delegated to, except where the behaviour is overwritten. </div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Craig</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 26 Jan 2016, at 12:05, Jonathon Horsman <<a href="mailto:jonathon@arctickiwi.com" class="">jonathon@arctickiwi.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi<div class=""><br class=""></div><div class="">Trying to understand Tempfile, so reading the docs:</div><div class=""><br class=""></div><div class=""><a href="http://docs.ruby-lang.org/en/2.2.0/Tempfile.html" class="">http://docs.ruby-lang.org/en/2.2.0/Tempfile.html</a><br class=""></div><div class=""><br class=""></div><div class="">I assume it's a subclass of IO, but I can't see any mention of this.</div><div class=""><br class=""></div><div class="">It does however say:</div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">Parent:</b></div><b class="">DelegateClass(File)</b><div class=""><b class=""><br class=""></b></div><div class="">what does this mean?</div><div class=""><br class=""></div><div class="">Thanks in advance</div><div class=""><br class=""></div><div class="">Jonno</div></div>
_______________________________________________<br class="">Chat mailing list<br class=""><a href="mailto:Chat@lists.lrug.org" class="">Chat@lists.lrug.org</a><br class="">Archives: http://lists.lrug.org/pipermail/chat-lrug.org<br class="">Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org<br class="">List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br class=""></div></blockquote></div><br class=""></div></body></html>