From: Philipp Meier Date: 2002-08-15T21:32:31+09:00 Subject: Re: adding method to existing class --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 15, 2002 at 09:20:24PM +0900, Eugene Scripnik wrote: > Now I want object blah (and other objects of some_class) to respond > to method some_method. I've tried to include module with my method > but I don't like evaling: >=20 > module Feature > def some_method > ... > end > end > some_class.class_eval { include Feature } > blah =3D some_class.new( 'anything' ) >=20 > Now blah responds to some_method. Is there way to include methods > without eval? class ExistingClass ... end ExistingClass.new.some_method # -> NameError: undefined method `some_method' for # module Feature def some_method ... end end class ExistingClass include Feature end ExistingClass.new.some_method # -> ok --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --y0ulUmNC+osPPQO6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9W59dfBriNoqItSYRAiBMAJ9op7wOvE3l19hafi2ku9MznH/GWACghOSp OlvN0MW3woiY2Lg9RzPcFOc= =Y46Y -----END PGP SIGNATURE----- --y0ulUmNC+osPPQO6--