From: Mark T on
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
#-----------------------------------------

--
MarkT

From: Marcin Wolski on
Mark T wrote:
> 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.
--
Posted via http://www.ruby-forum.com/.

From: Mark T on
Hi Marcin,
The String class is used as an example Class.
Could be anything.
Issue is in trying to (delete)/redefine a class.

> What are your trying to do? You want to extend String class? I ask,

MarkT

From: Marcin Wolski on
Mark T wrote:
> Hi Marcin,
> The String class is used as an example Class.
> Could be anything.
> Issue is in trying to (delete)/redefine a class.
>
>> What are your trying to do? You want to extend String class? I ask,
>
> MarkT

You can open existing class, and redefine methods. For example

#defined Soda class
class Soda
def initialize
@brand = "SweetenedSugar"

end

def retrieve_brand
return @brand
end
end


puts Soda.new.retrieve_brand
#this will return "SweetenedSugar"


#now, for example, you can open this class and redefine retrieve_brand
method
class Soda
def retrieve_brand
return @brand.upcase
end
end

puts Soda.new.retrieve_brand
#this will return "SWEETENEDSUGAR"


Hope this is what you want?
--
Posted via http://www.ruby-forum.com/.

From: Mark T on
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