# Re: Distruttore di classi

**URL:** <https://www.ruby-forum.com/t/re-distruttore-di-classi/148728>\
**Category:** IT\
**Created:** [September 16, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/re-distruttore-di-classi/148728 "2008-09-16T17:36:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriele\_renzi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e19b73/32.png) [@gabriele\_renzi](https://www.ruby-forum.com/u/gabriele_renzi)\
**Post date:** [September 16, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/re-distruttore-di-classi/148728/1 "2008-09-16T17:36:35Z")

</div>

> From: Luigi P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> in modo da poter anche fare Foo.new.process {|arg| … }

già che ci siamo, io farei

class Foo  
def initialize(args)  
…  
end  
def close  
…  
end  
def process(&block)  
block.call(self)  
ensure # def… end funziona come begin…end  
self.close()  
end

def self.process(args, &block) # classmethod  
new(args).process(&block)  
end

così da mimare l’interfaccia di File.open e simili:

Foo.process(something) do |foo|  
foo.stuff  
end
