"Janko Thyson" <janko.thy...@ku-eichstaett.de> writes:

> Dear list,
>
> just to make sure that I understand 'unregistering' methods for S4 reference
> classes correctly:
>
> If I registered a method and want to 'unregister' (i.e. remove) this method
> again, objects/instance created of the respective class still feature the
> removed method until I do an explicit reassign ('my.instance <-
> getRefClass("Classname")$new()'), right? 
>
> setRefClass("Shab", fields=list(a="numeric"))
> # Register method
> getRefClass("Shab")$methods(list(aSquare=function() a^2))
> getRefClass("Shab")$methods()
>
> # Create instance
> shab    <- getRefClass("Shab")$new()
> shab$a  <- 10
> # Use method
> shab$aSquare()
>
> # Remove method
> getRefClass("Shab")$methods(list(aSquare=NULL))
> getRefClass("Shab")$methods()         # Gone.
> shab$aSquare()                                # Still possible

If I am not mistaken methods are cached in the object during the first 
invocation.

So, if you change the method after the method has been used with the
instance. The object will not see the change.

This can not happen with the fields though, because they can not be installed
after the generator class is defined.

>
> shab    <- getRefClass("Shab")$new()
> shab$aSquare()                                # Not possible anymore
>
> Is it also possible to remove a method so that all instances do not feature
> the respective method anymore without having to resort to an explicit
> reassign? Or is this technically not possible or not a desired feature? 
>
> TIA,
> Janko
>
> ########## SYSTEM INFO ##########
> Windows XP SP3
> R 2.12.0 (patched as of 2010-11-22)
> Eclipse 3.6.1 (Helios)
> StatET 0.9.x
> ###############################

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to