--9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 02, 2012 at 12:39:28PM +0900, Nobuyoshi Nakada wrote: > Hi, > > (12/03/01 8:08), Aaron Patterson wrote: > > That's fine, except that if the String subclass implements initialize, > > the initialize method is never called on the new object: > > > > > > class TranslatedString < String > > def initialize str > > super > > @not_translated = true > > end > > Why negative predict? It's just an example. It could also be `needs_escaping` or `raw` or something like that. > > I would like to propose that we either: > > > > 1: Only return instances of String (as a superclass implementation) > > > > OR > > > > 2: Have `initialize_copy` or some other method called when the new > > string subclass is created. > > > > I prefer number #2. > > > > Here is a patch for #2. It may be naive, but my test passes: > > > > https://gist.github.com/1945213 > > Seems that patch would break other subclasses of String, whose > initialize_copy doesn't expect whole original string. When would this happen? I noticed that String#replace == String#initialize_copy. Why is that? Are people expected to write code like this? "foo".initialize_copy "bar" I can't think of any other cases where initialize_copy would be called by a string other than the original. -- Aaron Patterson http://tenderlovemaking.com/ --9amGYk9869ThD9tj Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJPUE7JAAoJEJUxcLy0/6/GvYIIAJihK6v4hd+6/KKLAsyNkG7S pqLYKRSDDGaWOnlwWyZpQ9IWegWigzBlGYUJ3cnqc4V2rnyioaBeJHEy8w/iOC5B 8DOL9R0Qm+hP243nKQE7nmFm7xM6e7BTKcP3lObo453R4vjh2xfiv6qETlVJSJMF eMZjBFPwQ/Qzw5f6+ZdxSOvu2jyyZZEc80hD8aQUq4ku+3qbTUwwYZUYUP+dpWqf asu0/7/X5wq9SP2XEiAqHlAuJHAjbDKhohsewMY4ayb2V9sOegsvG7hW+XREqvNY 8C5Zbp7Zf0yL9PcjPWsVEtjEO5+nI9bVS5azrVEf9XKZJhTW44s6a6/Hl7RhDswnV -----END PGP SIGNATURE----- --9amGYk9869ThD9tj--