logo       

Re: Where to 'declare' symbols: msg#00123

lang.smalltalk.squeak.beginners

Subject: Re: Where to 'declare' symbols

Hi Matthew,

Oh, duh! A method that simply returns a value *is* a simple solution. Thanks.

I just tried the class variable approach, too, (just to see how it works). It took me a while to figure out what you meant by initializing the Class but finally realized the only way to access the class variable was to do something like

MyClass initialize.
MyClass MySpecialConstant.

I guess inside a class method, you could access it like:

testValue > MySpecialConstant

Okay, I think I get it.

Thanks!

-- John


"First, and simplest, implement a message that returns the
constant:"

MyClass >> mySpecialNumber
^ 5



"Second, use a class pool variable:"

Object subclass: #MyClass
instanceVariableNames: ''
classVariableNames: 'MySpecialConstant'
poolDictionaries: ''
category: 'MyCategory'

"Set its value in the CLASS-SIDE initialize method:"

MyClass class >> initialize
MySpecialConstant := 5

"Don't forget to call MyClass initialize. Monticello will
automatically do this ONCE"

MyClass initialize




--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
_______________________________________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
jalmberg@xxxxxxxxxxx
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise