From: niklas | brueckenschlaeger Date: 2010-11-29T01:24:36+09:00 Subject: Re: abstract classes and modules --=-CAwzeURgaerFSBTu1GPE Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable (1) can be achieved by overwriting "new" on the class itself: class Foo class << self def new raise "Don't do that!" end end end class Bar < Foo end Foo.new #=3D> raises Bar.new #=3D> doesn't raise By (2) you probably mean simple namespacing... module X class Y end end Y #=3D> raises NameError X::Y #=3D> that's it. On Sun, 2010-11-28 at 19:15 +0900, Diego Virasoro wrote: > Hello, > for some code I am writing, I'd like to have a couple of abstract > classes. However I am not very sure how to go about it in Ruby. >=20 > Ideally all I would need is: > 1) The class cannot be instantiated > and/or > 2) The class is not visible outside of the module it comes in >=20 > What would be the canonical way to go about this in Ruby? Should I use > a mix-in module? >=20 > Ideally I would prefer to use a class since all the subclasses have a > similar instantiation so I'd like to code it only once and use > super(), but then the user himself may try to instantiate it breaking > the whole "magic". :) >=20 > Thank you > Diego >=20 --=-CAwzeURgaerFSBTu1GPE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAABAgAGBQJM8oI6AAoJEIQdQGZOjo8297AP/0mUpldFYeD03t3TSRoiE31a NORnJ9T1Lr5p3AUPxXvECHSVZ/nv+eHyHNs7dIgsfFKzujx+v1YNJl05P0Q45/wW YC/vWeocVCGv2zjDwAv0rygt6bAGjtiKA3sO7iJnCkmlVY/R5etGBLAYlb2P74Qa sRAJn5/UEnDT3CyHh3fkdvx6THvMxnqJ8vKGS7bAUbRthajQuW71taWPwLMmqkbD rBf2hZfFk5863GmwCSnumI7b932yxo2jCBSInvnuB67zUq0qPZzLjsJo2l9RbgDu 7Ozv6d8hYv33X5Qd+ypV4HiUtjFw1Tm2I200sqcc/dXZIsB148/gwBuzxxB0v+FH BswUSA3ng53/kCMnjxHUjgQ2FOC0hmoiPkXYGjjXHzx08g9sd0bitEGUimp/y//v t4qwJN7/a9uABrlPClyULUnD89ljq2UH3Y67Hs9pLGeO81MKyh5xahC0g/SB5Sti 0uO3O7+7SHRK7pEtGV0Rniv5jAnUhQbLM7uuytyJk7HeUJV9XUbVelgfodIUSBw6 5L1mYbMKQDN8ncw2x8AtRw+rBgGGfPH6AAXLbNkfTJTNnPo48dcj6qStfDoQb8Np 0xTb6K1DuO1YmPDxo+kEZjTL9XuxbGri6NmS/ZwnFyjvnavtwGkqbXGRfb3uFG9I ftjMvl90fHlO3+nh4EVX =F2HX -----END PGP SIGNATURE----- --=-CAwzeURgaerFSBTu1GPE--