Re: [Newbies] mix ins

2016-08-02 Thread Bert Freudenberg
On Tue, Aug 2, 2016 at 5:03 PM, Joseph Alotta 
wrote:

> Greetings,
>
> I want to add a method to the Array class.
>
> #(‘abc’ ‘def’) join =>  ‘abcdef’
>
> #(‘abc’ ‘def’) join: $/ => ‘abc/def’
>
> I am afraid that if I add it to Array directly, it will get lost in a new
> update.  I want to keep it in my project area.
>
> In ruby, this is called a “mix in”.
>
> How can I do this?
>

Firstly, these methods exist already.  They are defined in
SequencableCollection, a  superclass of Array, so Array inherits them:

#('abc' 'def') join => 'abcdef'

#('abc' 'def') joinSeparatedBy: '/' => 'abc/def'

Secondly, if you wanted to add these (or other methods), they would not be
lost by updating. That is, unless the update specifically includes a method
of the same name in the same class. Updating only adds and removes methods,
it doesn't "reset" the whole class.

Thirdly, to keep these "extension methods" in your own package, put them in
a method category that starts with an asterisk followed by your package
name. That is, if your Monticello package is named "Foo-Bar", then put your
"mix in" Array methods into the category "*foo-bar" which will mark them as
belonging to your package, not the package the Array class is in. The
extension methods will be stored and loaded with your package.

Have fun!

- Bert -
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] mix ins

2016-08-02 Thread Joseph Alotta
Greetings,

I want to add a method to the Array class.

#(‘abc’ ‘def’) join =>  ‘abcdef’

#(‘abc’ ‘def’) join: $/ => ‘abc/def’

I am afraid that if I add it to Array directly, it will get lost in a new 
update.  I want to keep it in my project area.

In ruby, this is called a “mix in”.

How can I do this?

Sincerely,

Joe.



___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners