From: Robert Klemme Date: 2004-03-31T16:29:23+09:00 Subject: Re: Silly question... "Simon Strandgaard" schrieb im Newsbeitrag news:pan.2004.03.31.06.29.43.124211@adslhome.dk... > On Wed, 31 Mar 2004 07:20:18 +0000, GGarramuno wrote: > > Is there any way of completely remove a class object's methods instead of > > extending the class? > [snip] > > I'm finding the above to be a major pain when debugging and prototyping new > > code in either irb or an embedded ruby, every time I reload a library. > > > Will an 'alias' help you? like this > > server> ruby a.rb > 1 > 3 > 1 > server> cat a.rb > class A > attr :t > def initialize > @t = 1 > end > end > a = A.new > puts a.t # => 1 > > # Not extending... redefining here.... > class A > attr :x > alias old_initialize initialize > def initialize > old_initialize > @x = 3 > end > end > a = A.new > puts a.x # => 3 > puts a.t # => 1 > server> I don't think that's what the OP wanted. This seems to be more appropriate class A attr :t def initialize @t = 1 end end a = A.new puts a.t # => 1 # Not extending... redefining here.... class A remove_method :t attr :x def initialize @x = 3 end end a = A.new puts a.x # => 3 puts a.t # => error, instead of outputing nil yields irb(main):022:0> puts a.t # => error, instead of outputing nil NoMethodError: undefined method `t' for # from (irb):22 from :0 Regards robert