hard reset class variable state

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

hard reset class variable state

Ben Coman
I want to reset all the class variables in an application to nil.
I've got as far as finding them, for example...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
stateToReset := packages flatCollect: [:p| 
p definedClasses 
select:[:c | (c classVarNames size > 0) and: [(c name includesSubstring: 'Configuration') not]]
thenCollect:[:c| c-> c classVarNames]
].
stateToReset asDictionary keysAndValuesDo:[:class :variables|
variables do: [:v| Transcript crShow: 'Clear ', class printString, ' -> ' , v printString].
].

What could go in place of the Transcript line to set them to nil?

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: hard reset class variable state

Guillermo Polito
Actually class variables are stored in a dictionary in a class. You can access that by saying:

  aClass classPool.

So resetting all values of a class variable could be easily done with something like

 aClass classPool keys do: [ :k | aClass classPool at: k put: nil ].

Maybe that could be a nice addition.

On Sat, Jul 29, 2017 at 9:51 AM, Ben Coman <[hidden email]> wrote:
I want to reset all the class variables in an application to nil.
I've got as far as finding them, for example...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
stateToReset := packages flatCollect: [:p| 
p definedClasses 
select:[:c | (c classVarNames size > 0) and: [(c name includesSubstring: 'Configuration') not]]
thenCollect:[:c| c-> c classVarNames]
].
stateToReset asDictionary keysAndValuesDo:[:class :variables|
variables do: [:v| Transcript crShow: 'Clear ', class printString, ' -> ' , v printString].
].

What could go in place of the Transcript line to set them to nil?

cheers -ben




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: +33 06 52 70 66 13

Reply | Threaded
Open this post in threaded view
|

Re: hard reset class variable state

Ben Coman
thx guille.

On Sat, Jul 29, 2017 at 9:40 PM, Guillermo Polito <[hidden email]> wrote:
Actually class variables are stored in a dictionary in a class. You can access that by saying:

  aClass classPool.

So resetting all values of a class variable could be easily done with something like

 aClass classPool keys do: [ :k | aClass classPool at: k put: nil ].

Maybe that could be a nice addition.

On Sat, Jul 29, 2017 at 9:51 AM, Ben Coman <[hidden email]> wrote:
I want to reset all the class variables in an application to nil.
I've got as far as finding them, for example...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
stateToReset := packages flatCollect: [:p| 
p definedClasses 
select:[:c | (c classVarNames size > 0) and: [(c name includesSubstring: 'Configuration') not]]
thenCollect:[:c| c-> c classVarNames]
].
stateToReset asDictionary keysAndValuesDo:[:class :variables|
variables do: [:v| Transcript crShow: 'Clear ', class printString, ' -> ' , v printString].
].

What could go in place of the Transcript line to set them to nil?

cheers -ben




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13


Reply | Threaded
Open this post in threaded view
|

Re: hard reset class variable state

Ben Coman
btw, for the archives, I ended up using...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
packages do: [:p| p definedClasses do:[:class| 
class classPool keys do: [ :k | class classPool at: k put: nil ] ]].

cheers -ben

On Sat, Jul 29, 2017 at 11:22 PM, Ben Coman <[hidden email]> wrote:
thx guille.

On Sat, Jul 29, 2017 at 9:40 PM, Guillermo Polito <[hidden email]> wrote:
Actually class variables are stored in a dictionary in a class. You can access that by saying:

  aClass classPool.

So resetting all values of a class variable could be easily done with something like

 aClass classPool keys do: [ :k | aClass classPool at: k put: nil ].

Maybe that could be a nice addition.

On Sat, Jul 29, 2017 at 9:51 AM, Ben Coman <[hidden email]> wrote:
I want to reset all the class variables in an application to nil.
I've got as far as finding them, for example...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
stateToReset := packages flatCollect: [:p| 
p definedClasses 
select:[:c | (c classVarNames size > 0) and: [(c name includesSubstring: 'Configuration') not]]
thenCollect:[:c| c-> c classVarNames]
].
stateToReset asDictionary keysAndValuesDo:[:class :variables|
variables do: [:v| Transcript crShow: 'Clear ', class printString, ' -> ' , v printString].
].

What could go in place of the Transcript line to set them to nil?

cheers -ben




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13



Reply | Threaded
Open this post in threaded view
|

Re: hard reset class variable state

Ben Coman
btw2, I submitted this to PharoLauncher repo. 
cheers -ben

On Thu, Aug 3, 2017 at 9:42 PM, Ben Coman <[hidden email]> wrote:
btw, for the archives, I ended up using...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
packages do: [:p| p definedClasses do:[:class| 
class classPool keys do: [ :k | class classPool at: k put: nil ] ]].

cheers -ben

On Sat, Jul 29, 2017 at 11:22 PM, Ben Coman <[hidden email]> wrote:
thx guille.

On Sat, Jul 29, 2017 at 9:40 PM, Guillermo Polito <[hidden email]> wrote:
Actually class variables are stored in a dictionary in a class. You can access that by saying:

  aClass classPool.

So resetting all values of a class variable could be easily done with something like

 aClass classPool keys do: [ :k | aClass classPool at: k put: nil ].

Maybe that could be a nice addition.

On Sat, Jul 29, 2017 at 9:51 AM, Ben Coman <[hidden email]> wrote:
I want to reset all the class variables in an application to nil.
I've got as far as finding them, for example...

packages := RPackageOrganizer default packages select:[:p|
(p name includesSubstring: 'PharoLauncher') ].
stateToReset := packages flatCollect: [:p| 
p definedClasses 
select:[:c | (c classVarNames size > 0) and: [(c name includesSubstring: 'Configuration') not]]
thenCollect:[:c| c-> c classVarNames]
].
stateToReset asDictionary keysAndValuesDo:[:class :variables|
variables do: [:v| Transcript crShow: 'Clear ', class printString, ' -> ' , v printString].
].

What could go in place of the Transcript line to set them to nil?

cheers -ben




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13