Re: Adding a string to string array's indexes with ruby; how
Posted: Wed Mar 11, 2020 7:54 pm
RJHollins wrote:Let me ask ... do you just enclose the whole thing into a new module, and then put that into the toolbox ?
Yes
DSP Robotics and FlowStone Graphical Programming Software Support and Forums
https://dsprobotics.com/support/
RJHollins wrote:Let me ask ... do you just enclose the whole thing into a new module, and then put that into the toolbox ?
kortezzzz wrote:RJHollins wrote:Let me ask ... do you just enclose the whole thing into a new module, and then put that into the toolbox ?
Yesof course, I first name the enclosed module with my own key words, so whenever I need it, I can't do any mistakes. I'll find it. This may sound as a very primitive and non-elegant solution, but it works for me
pshannon wrote:Everyone's code earlier was great, but here is a simple module. I hope it helps.
Open the module and a help file plus code is in there with a reference. Ruby is not my first language of choice, however, it is what we have for FS and it brings designs to the next level.
pshannon wrote:Everyone's code earlier was great, but here is a simple module. I hope it helps.
Open the module and a help file plus code is in there with a reference. Ruby is not my first language of choice, however, it is what we have for FS and it brings designs to the next level.
Code: Select all
"text" << "newtext"Code: Select all
"text" + "newtext"tulamide wrote:pshannon wrote:Everyone's code earlier was great, but here is a simple module. I hope it helps.
Open the module and a help file plus code is in there with a reference. Ruby is not my first language of choice, however, it is what we have for FS and it brings designs to the next level.
I love your attitude! You surely don't lack self-confidence, Mr Coolhacker![]()
I hope you don't mind, but there was a reason I usedCode: Select all
"text" << "newtext"
and notCode: Select all
"text" + "newtext"
It's a little trick to save some time. It adds up the longer the array is, so it's worth it. text + newtext tells Ruby to create a new string class with the combined text and newtext.
Whereas text << newtext tells Ruby to use the already existing class and just append newtext. That saves you the time and memory needed to create a class instance.
If you would change your module to do that as well, it will be a good tool for the toolbox.
I like that. You don't get such a nickname by accident!pshannon wrote:I work in cyber security for the past 16 years and someone once called me "Coolhacker" and it stuck.
We could use a lot more of your kind on the Ruby front. It seems lately there's only trog and I left to help. It can become a little too much at times. So, any other helping hand is welcome.pshannon wrote:It looked like someone really needed help with this.
I didn't spend enough time on your code, and that's why my tip didn't work as you would wish.pshannon wrote:I did try your suggestion for optimized code which is always welcomed. For some reason it kept adding more strings and produced unpredictable results. It did work well with the static arrays like you demonstrated, I wonder if the green string array outputs something different?