Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7360

Re: Ruby class and ensure

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: Ruby class and ensure
Date 2017-06-24 11:24 +0200
Message-ID <er6pdpFb2m1U1@mid.individual.net> (permalink)
References <oigo29$6hq$1@shakotay.alphanet.ch>

Show all headers | View raw


On 22.06.2017 17:34, Une Bévue wrote:
> I've to write a class opening remote session, and I wonder if it is 
> possible to write it such a way that ensure a closing session ?
> 
> say I've a class :
> 
> class Toto
> 
>    def self.open
>      // do the job to open a session
>    end
> 
>    def self.getSomething
>      return something
>    end
> 
>    def self.close
>      // close the session
>    end
> 
> end

I do not think it is wise to use class methods for that.  I'd rather 
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 
> used (it supposes a certain amount of time ?)

http://ruby-doc.org/stdlib-2.4.1/libdoc/timeout/rdoc/index.html

Cheers

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Ruby class and ensure Une Bévue <unbewusst.sein@fai.invalid> - 2017-06-22 17:34 +0200
  Re: Ruby class and ensure Robert Klemme <shortcutter@googlemail.com> - 2017-06-24 11:24 +0200
    Re: Ruby class and ensure Une Bévue <unbewusst.sein@fai.invalid> - 2017-06-25 16:17 +0200

csiph-web