--1926193751-376386811-12309148131697 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-376386811-1230914813=:31697" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-376386811-12309148131697 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sat, 3 Jan 2009, Tom Link wrote: >> ¨ÂïäõìÍùÇóõâÂáîç >> ¨Âåæ çóõ⡨ªáòçó¬ ¦âìïãë>> ¨Âõðåò¨ªáòçó¦âìïãëüü óåìæ >> ¨Âîä >> ¨Âîä >> >> ¨Âôò ¢áâ㢮åøôåîä¨ÍùÇóõâÂáîç© > > str += "1" > > This would return a normal string. You'd then have to extend those > strings again and again. Please correct me if I'm wrong but IMHO this > approach brings little advantage over defining a subclass of String: > > class MyString < String > ... > end > > str = MyString.new("abc") > > This creates a copy of "abc" in this particular case but provides IMHO > more flexibility. With some extra work you could catch those cases > where the function returns a new string, eg something in the line of: > > class MyString < BasicObject > > YOUR METHODS HERE > > def method_missing(...) > ... > end > > end > > The extra indirection has its drawbacks of course. If you're really finding it necessary to create a whole class and a method_missing apparatus to make gsub! chainable, it's probably a sign something needs to be rethought :-) Part of the point of the #extend technique is that it requires pin-pointing what you actually need -- that is, which objects have to do what -- so it's definitely not the same kind of solution as subclassing and/or changing existing classes. > The conclusion IMHO is twofold: (1) "monkey patching" is ok if you're > the only user of your code (in which case it is okay to use a silly > name for that practice) or if the extensions are part of a well > documented supplementary library/framework where those extended > methods become some sort of standard. (2) Beware of people who are > proud of their monkey tactics. I wouldn't change gsub! globally even if I'm the only user of my code, because it's more a question of what other code *I* use (core Ruby code, other libraries). They may be using gsub! as documented. (And of course that's just one example.) David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management! --1926193751-376386811-12309148131697-- --1926193751-376386811-12309148131697--