--WYTEVAkct0FjGQmd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 05, 2012 at 12:28:38AM +0900, headius (Charles Nutter) wrote: >=20 > Issue #4264 has been updated by headius (Charles Nutter). >=20 >=20 > Yusuke: Individual classes can (and often should) still define their own = to_a, etc. There's no reason to move the current logic into a slower case/w= hen statement. >=20 > The convert_to(cls) method would just be a standard way to allow new libr= aries to handle arbitrary object types without monkey-patching. For example= , rather than monkey-patching a to_xml into Object or BasicObject, an XML l= ibrary could just define XML.convert(obj) that contains that logic. Users w= ould then just call obj.convert_to(XML). So implementation would just be something like this: class Object def convert_to obj obj.convert self end end It seems very nice. Hopefully it would discourage people from monkey patching things like `to_json` on to object. This type of monkey patching is a real world problem we (the Rails team) has to deal with. Several JSON libraries would implement `to_json`, and when people had them both activated at the same time, things would explode. Fortunately we've worked around those issues. I think this will help mitigate the "multi-monkey patch" problem, but as long as people can monkey patch, those types of bugs will happen. :( --=20 Aaron Patterson http://tenderlovemaking.com/ --WYTEVAkct0FjGQmd Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJPfJgpAAoJEJUxcLy0/6/GMjYH/jy3ZYBeIa8rBeNJhAVefjmT WpC4zqZTR2I7V8zZSOU2pCO9OWE7TzkbTkG2wjk92NqfjArIO3H2EJWyDA8aTqcW l/yWQfoumIfP6Xkixin0fQjhRLh1x1uJZc6Gx/DtlXdIWcGWZjOas87isD2c4gRF 9/IDMmfGl6lzUDsuqUMDfW7uIZ6EBifwVC272xZSHFsjHzcCtUzBuZGXNLOdP7wV qOpRHDHk4NbxGlwNisBSEA0ag6k3ywszGlBJDFN6+n5UxgO3oHry5ShRII64QNUy 6ZSOWkq0ZF1BEJx8f2mxaQpVwtw9WMm8COxbcdiZT6k/ep6BbmNqwzK71ApdHEY= =yzQX -----END PGP SIGNATURE----- --WYTEVAkct0FjGQmd-- On Thu, Apr 05, 2012 at 12:28:38AM +0900, headius (Charles Nutter) wrote: >=20 > Issue #4264 has been updated by headius (Charles Nutter). >=20 >=20 > Yusuke: Individual classes can (and often should) still define their own = to_a, etc. There's no reason to move the current logic into a slower case/w= hen statement. >=20 > The convert_to(cls) method would just be a standard way to allow new libr= aries to handle arbitrary object types without monkey-patching. For example= , rather than monkey-patching a to_xml into Object or BasicObject, an XML l= ibrary could just define XML.convert(obj) that contains that logic. Users w= ould then just call obj.convert_to(XML). So implementation would just be something like this: class Object def convert_to obj obj.convert self end end It seems very nice. Hopefully it would discourage people from monkey patching things like `to_json` on to object. This type of monkey patching is a real world problem we (the Rails team) has to deal with. Several JSON libraries would implement `to_json`, and when people had them both activated at the same time, things would explode. Fortunately we've worked around those issues. I think this will help mitigate the "multi-monkey patch" problem, but as long as people can monkey patch, those types of bugs will happen. :( --=20 Aaron Patterson http://tenderlovemaking.com/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJPfJgpAAoJEJUxcLy0/6/GMjYH/jy3ZYBeIa8rBeNJhAVefjmT WpC4zqZTR2I7V8zZSOU2pCO9OWE7TzkbTkG2wjk92NqfjArIO3H2EJWyDA8aTqcW l/yWQfoumIfP6Xkixin0fQjhRLh1x1uJZc6Gx/DtlXdIWcGWZjOas87isD2c4gRF 9/IDMmfGl6lzUDsuqUMDfW7uIZ6EBifwVC272xZSHFsjHzcCtUzBuZGXNLOdP7wV qOpRHDHk4NbxGlwNisBSEA0ag6k3ywszGlBJDFN6+n5UxgO3oHry5ShRII64QNUy 6ZSOWkq0ZF1BEJx8f2mxaQpVwtw9WMm8COxbcdiZT6k/ep6BbmNqwzK71ApdHEY= =yzQX -----END PGP SIGNATURE-----