Currently this raises: superclass mismatch for class Soda (TypeError)
How can I redefine a class?
As a class is an object, if I remove all of it's methods, attr & @'s
could it be GC'd? (
···
#-----------------------------------------
class Soda
def initialize @brand = "SweetenedSugar" end
def retrieve_brand
return @brand end end
class Soda < String
end #-----------------------------------------
Currently this raises: superclass mismatch for class Soda (TypeError)
How can I redefine a class?
As a class is an object, if I remove all of it's methods, attr & @'s
could it be GC'd? ( #-----------------------------------------
class Soda
def initialize @brand = "SweetenedSugar" end
def retrieve_brand
return @brand end end
class Soda < String
end #-----------------------------------------
What are your trying to do? You want to extend Stirng class? I ask,
because at the moment I see that you are trying to define Soda class
twice. First definition is a standalone class, and the second by
extending String class.
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.....
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.....
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
irb(main):007:0> class Soda < String
irb(main):008:1> end
=> nil
Jesus.
···
On Tue, May 25, 2010 at 9:18 AM, Mark T <paradisaeidae@gmail.com> wrote:
from :0
Where did I have my head? send remove_const to Object for top level
constants and for all other to their defining module object, of
course. Sorry got confused with irb output - that is waaay of a bad
excuse I know
Cheers
R.
···
2010/5/25 Jesús Gabriel y Galán <jgabrielygalan@gmail.com>:
Could very well be :-).
I just saw that remove_const was a method in Module and I thought:
self.class is a Module, so I'll use that.
--
The best way to predict the future is to invent it.
-- Alan Kay