On Sep 11, 2012, at 8:52 PM, Camillo Bruni wrote:

> On 2012-09-11, at 20:50, Benjamin <benjamin.vanryseghem.ph...@gmail.com> 
> wrote:
>> On Sep 11, 2012, at 8:41 PM, Camillo Bruni wrote:
>>> On 2012-09-11, at 20:36, sergio_101 <sergio....@gmail.com> wrote:
>>>> yes, i know this sounds simple.. but is it possible to instantiate an
>>>> object with some parameters?
>>>> 
>>>> say i have a dictionary:
>>>> 
>>>> params := Dictionary new.
>>>> params at: 'sound' put: 'bark'
>>>> 
>>>> dog := Dog new.
>>>> 
>>>> ^^ at this point, i would like to just create a dog and send it
>>>> 'params' all at once..
>>>> 
>>>> can i do this? what would the syntax look like?
>>> 
>>> sure :) in Smalltalk (almost) everything is a message-send :)
>>> 
>>> So you can do the following:
>>> 
>>> dog := Dog sound: 'wuff'.
>>> 
>>> then a class side method:
>>> 
>>> Dog class >> #sound: aString
>>>     ^ self basicNew
>>>             initializeWithSound: aString;
>>                      yourself.
>> 
>> Otherwise you may have some strange behavior if the #initializeWithSound: 
>> message doesn't return the receiver :)
> well initialize.* usually returns self :) (it's like #initialize, where you 
> never send #yourself)

Play with Morphic and then you will take this habit too :)

Ben


Reply via email to