From: Sebastian Hungerecker Date: 2009-01-28T08:27:52+09:00 Subject: Re: String doesnt auto dup on modification Simon Krahnke wrote: > * Mike Gold (2009-01-23) schrieb: > > String.public_instance_methods(false).grep(/!/).map(&:to_sym) + > > Is that a new feature? Symbol#to_proc is new in ruby core since 1.8.7+. It had been previously defined by ActiveSupport and, I think, facets. > make the to_sym method act as block. Which to_sym method? The to_sym method of each item in the array. symbol_to_proc is defined somewhat like: lambda {|x, *args| x.send(self, *args)} So foo.map(&:to_sym) behaves like foo.map {|x| x.send(:to_sym)} > > DESTRUCTIVE_METHODS.each { |m| > > define_method(m) { |*args, &block| > > __setobj__(__getobj__.dup) > > __getobj__.send(m, *args, &block) > > WTF? What's this __[gs]etobj__ about? Those are methods defined by DelegateClass(). They are used to get and set the object that is delegated to. In this case they cause the proxy-object to delegate to a copy of the original string instead of the original string itself when a destructive method is called. HTH, Sebastian -- NP: Metallica - Jump In The Fire Jabber: sepp2k@jabber.org ICQ: 205544826