From: Marcin Wolski on 25 May 2010 03:33 Mark T wrote: > I'm looking for something... kinda 'destructive'.... > > class Soda > def initialize > @brand = "SweetenedSugar" end > > def retrieve_brand > return @brand end end > > Soda.removeClassAndMethods # yet to be (found) or > implemented method..... > > irb(main):001:0> Soda.retrieve_brand > NameError: uninitialized constant Soda > from (irb):1 > #---------------------------- ^ yep, this error is what I'm looking > for..... > > MarkT You can remove a method as follows: class Soda remove_method :retrieve_brand end -- Posted via http://www.ruby-forum.com/.
From: Robert Dober on 25 May 2010 03:46 On Tue, May 25, 2010 at 9:18 AM, Mark T <paradisaeidae(a)gmail.com> wrote: IIUC you want Soda = Class::new do def a; 42 end end Soda = Class::new( String ) do # Completely new class here, the old can indeed be GCed end You will get a const redefined warning, but if that hurts there are solutions, just probably out of topic here. HTH R. -- The best way to predict the future is to invent it. -- Alan Kay
From: Jesús Gabriel y Galán on 25 May 2010 04:23 On Tue, May 25, 2010 at 9:18 AM, Mark T <paradisaeidae(a)gmail.com> wrote: > I'm looking for something... kinda 'destructive'.... > > class Soda > def initialize > @brand = "SweetenedSugar" end > > def retrieve_brand > return @brand end end > > Soda.removeClassAndMethods # yet to be (found) or > implemented method..... > > irb(main):001:0> Soda.retrieve_brand > NameError: uninitialized constant Soda > from (irb):1 > #---------------------------- ^ yep, this error is what I'm looking for..... irb(main):001:0> class Soda irb(main):002:1> end => nil irb(main):005:0> self.class.send(:remove_const,:Soda) => Soda irb(main):006:0> Soda NameError: uninitialized constant Soda from (irb):6 from :0 irb(main):007:0> class Soda < String irb(main):008:1> end => nil Jesus.
From: Mark T on 25 May 2010 04:29 Thanks all!! MarkT
From: Robert Dober on 25 May 2010 10:56 2010/5/25 Jesús Gabriel y Galán <jgabrielygalan(a)gmail.com>: > irb(main):005:0> self.class.send(:remove_const,:Soda) should that not rather be Object.send .... R.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: [ANN] mkmf-lite 0.1.0 Next: lime wire pro Full very speed ...new Versiyon |