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

On Thu, Jan 12, 2006 at 02:40:40AM +0900, Christer Nilsson wrote:
> Is it possible to catch index out of range ?
> I managed to redefine Array, but I want to have both possibilities.

You can use a delegator:

require 'delegate'

class SafeArray < DelegateClass(Array)
  def [](index)
    raise "index error" if index.abs > ize
    super(index)
  end
end

regards,
Ed

--SLDf9lqlvOQaIe6s
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)

iD8DBQFDxUYYnhUz11p9MSARAr7YAJ4pOiznxR05O3MRKBdAgM1+y+iUkACeJ9kf
adda4c+s+1uOh6qHI9krorMpw
-----END PGP SIGNATURE-----

--SLDf9lqlvOQaIe6s--