Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Ruby class and ensure Date: Sat, 24 Jun 2017 11:24:08 +0200 Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net EuAELaCHXXF3fnJiEv0sXQFzm4sZbZpUs3y1b6L8CPxWv5SlE= Cancel-Lock: sha1:bk00lBspQggD5I11BRcJ8xzlvPM= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 In-Reply-To: Content-Language: de-DE Xref: csiph.com comp.lang.ruby:7360 On 22.06.2017 17:34, Une B=C3=A9vue wrote: > I've to write a class opening remote session, and I wonder if it is=20 > possible to write it such a way that ensure a closing session ? >=20 > say I've a class : >=20 > class Toto >=20 > def self.open > // do the job to open a session > end >=20 > def self.getSomething > return something > end >=20 > def self.close > // close the session > end >=20 > end I do not think it is wise to use class methods for that. I'd rather=20 create an instance for that - even if it is a singleton or assigned to a = global variable. > I'd like to have Toto.close automatically called when no more method=20 > used (it supposes a certain amount of time ?) http://ruby-doc.org/stdlib-2.4.1/libdoc/timeout/rdoc/index.html Cheers robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/