<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 2, 2016 at 5:03 PM, Joseph Alotta <span dir="ltr">&lt;<a href="mailto:joseph.alotta@gmail.com" target="_blank">joseph.alotta@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Greetings,<br>
<br>
I want to add a method to the Array class.<br>
<br>
#(‘abc’ ‘def’) join =&gt;  ‘abcdef’<br>
<br>
#(‘abc’ ‘def’) join: $/ =&gt; ‘abc/def’<br>
<br>
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.<br>
<br>
In ruby, this is called a “mix in”.<br>
<br>
How can I do this?<br></blockquote><div> </div><div>Firstly, these methods exist already.  They are defined in SequencableCollection, a  superclass of Array, so Array inherits them:</div><div><br></div><div><div>#(&#39;abc&#39; &#39;def&#39;) join =&gt; &#39;abcdef&#39;</div><div><br></div><div>#(&#39;abc&#39; &#39;def&#39;) joinSeparatedBy: &#39;/&#39; =&gt; &#39;abc/def&#39;</div></div><div><br></div><div>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&#39;t &quot;reset&quot; the whole class.</div><div><br></div><div>Thirdly, to keep these &quot;extension methods&quot; 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 &quot;Foo-Bar&quot;, then put your &quot;mix in&quot; Array methods into the category &quot;*foo-bar&quot; 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.</div><div><br></div><div>Have fun!</div><div><br></div><div>- Bert -</div><div><br></div></div></div></div>