From: Charles Oliver Nutter Date: 2007-07-13T15:55:40+09:00 Subject: Re: Proposal: runtime-modifying Kernel methods should be keywords Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Proposal: runtime-modifying Kernel methods should be keywords" > on Fri, 13 Jul 2007 15:42:06 +0900, Charles Oliver Nutter writes: > > |I'd say anything that fits both of the following criteria qualifies: > | > |- the feature can't be implemented without knowing how to manipulate > |runtime/implementation-specific structures (and having a way to > |manipulate those structures) > |- the feature can't be wrapped in another method and maintain the same > |behavior as if it were called in the original context > | > |All those listed so far fit these criteria. > > String#gsub ? gsub needs access to internal structures (namely, the in-memory representation of a String) but it can successfully be wrapped with another method. I think both criteria must be met, since being able to wrap a method means it's not doing anything weird with the caller's logical binding/frame/scope. class String def my_gsub(*x) if block_given? gsub(*x) {|y| yield y} else gsub(*x) end end end - Charlie