[LRUG] Understanding Ruby Tempfile documentation
Craig R Webster
craig at xeriom.net
Tue Jan 26 04:32:14 PST 2016
Looks like it’s Ruby all the way down:
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):
def initialize basename, temp_dir = '/tmp'
file_name = [ basename, rand(1_000_000_000), Time.now.to_f ].join('-')
file_path = File.join temp_dir, file_name
@file = File.open file_path, ...
def method_missing name, *args
@file.send name, *args
def respond_to? name
The resulting class will support the same API and behaviour as the class delegated to, except where the behaviour is overwritten.
> On 26 Jan 2016, at 12:05, Jonathon Horsman <jonathon at arctickiwi.com> wrote:
> Trying to understand Tempfile, so reading the docs:
> http://docs.ruby-lang.org/en/2.2.0/Tempfile.html <http://docs.ruby-lang.org/en/2.2.0/Tempfile.html>
> I assume it's a subclass of IO, but I can't see any mention of this.
> It does however say:
> what does this mean?
> Thanks in advance
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Chat