--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Nov 02, 2005 at 02:43:08AM +0900, Detlef Reichl wrote:
> Is there a more elegant way to free the resources automatically, as to
> create a special free or close method for my object?

Yes.  Write an open method that takes a block:

def open(device_name)
  dev  o_the_opening(device_name)
  yield dev
  do_the_closing(dev)
end

And use it like this:

MyDevice.open("/dev/foo") do |dev|
  dev.write('bar')
  puts dev.read
end

regards,
Ed

--TB36FDmn/VVEgNH/
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDZ6u+nhUz11p9MSARAvdVAJ9RAgrOtpKsw5hAORCA+yrpbOExYwCbB+9h
RoiKLY7lrH4ob6SX0YqNux8wk
-----END PGP SIGNATURE-----

--TB36FDmn/VVEgNH/--