From: "framefritti@..." Date: 2008-01-10T21:54:58+09:00 Subject: Re: how to remove a method from an object ? Brian.LeRoux ha scritto: > class Server > attr_accessor :shh > > def initialize(f=false) > @shh = f > end > > def print > if @shh > self.send(:method_missing) > else > puts 'hi there' > end > end > > def method_missing > puts 'I look forward to seeing better ways of doing this!' > end > # > end > > s = Server.new > s.print > > s2 = Server.new(true) > s2.print > > s.print > > > > > On Jan 10, 12:32�am, Valerio Schiavoni > wrote: > > hello everyone, > > > > how can I remove a method from an object, without impacting future > > instances of its class ? > > > > say: > > > > class Server > > � �def print > > � � � �puts 'hello' > > � �end > > end > > > > s1 = Server.new > > s1.print #this work > > > > #now remove print from s1 somehow.. > > > > s1.print #this should hit method_missing > > > > s2 = Server.new > > s2.print # this should work fine as well... > > > > Thanks for any help Maybe it is not what the original post asked for, but I could not resist... class Server def initialize(add_print_method=false) if (add_print_method) def self.print puts "Hi #{self.object_id.to_s(16)}"; end end puts "Object #{self.object_id.to_s(16)} created" end end a=Server.new(true) b=Server.new a.print # prints "Hi ..." b.print # raises NoMethodError