If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
class array methodes expansion
9 posts
• Page 1 of 1
class array methodes expansion
after tiffy and billv were posting some ruby tools and a lot of questions about array handling i was born the idea of an array methode expansion for easier array manipulation..
i added 9 new methodes to the array class which where asked in the forum or i needed already by my own, all methodes are available as nondestructive and destructive methodes..
for sure there are a lot of more useful methodes to add which are not already exist in the array class
i added 9 new methodes to the array class which where asked in the forum or i needed already by my own, all methodes are available as nondestructive and destructive methodes..
for sure there are a lot of more useful methodes to add which are not already exist in the array class
- Attachments
-
- Array-Class-Methodes-Expansion.fsm
- (5.32 KiB) Downloaded 1070 times
Last edited by Nubeat7 on Wed Dec 19, 2018 5:17 pm, edited 12 times in total.
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: class array methodes expansion
Oh this is going to be nice and handy !! Thanks NuBeat !
I can think of a list of array handling within RUBY that would be great for toolbox.
What I don't know is whether they would fall under the 'Class' method.
For example: adding arrays, sorting, searching for item or items. Pretty much wringing out every possible need we'd have when dealing with arrays.
One idea is to make a RUBY code data base that would have linked arrays with wildcard searching, editing, copy/paste ... the gamut.
I'm sure there are some great, useful ideas out there.
Always appreciate your comments and contributions !!!
Big Thanks!
I can think of a list of array handling within RUBY that would be great for toolbox.
What I don't know is whether they would fall under the 'Class' method.
For example: adding arrays, sorting, searching for item or items. Pretty much wringing out every possible need we'd have when dealing with arrays.
One idea is to make a RUBY code data base that would have linked arrays with wildcard searching, editing, copy/paste ... the gamut.
I'm sure there are some great, useful ideas out there.
Always appreciate your comments and contributions !!!
Big Thanks!
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: class array methodes expansion
Thanks newbeat7...
BV MUSIC SYDNEY AUSTRALIA..Songwriting and Software development
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
- billv
- Posts: 1157
- Joined: Tue Aug 31, 2010 3:34 pm
- Location: Australia
Re: class array methodes expansion
RJHollins wrote:For example: adding arrays, sorting, searching for item or items. Pretty much wringing out every possible need we'd have when dealing with arrays.
..
lot of this stuff is already handled in the arrayclass, stuff like join, shift, sort, map ....
it is well documented here:
http://ruby-doc.org/core-2.0.0/Array.html
the idea is to write useful methodes which are not here already, often they are combinations of existing methodes or just a map function with a specified block but also some specific sorts could be of interest or some string handling..
i also thought about putting prefixes for specific methodes like "str_array_methode_name" instead just "array_methode_name" when it is a methode to handle strings, i think some kind of norm would be a good idea here.
it is also about to not occupy every possible methodename...
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: class array methodes expansion
found a mistake in the set_to_range methode, forgot the braces...
note that this methode only works right for 0..1 values!
any body have an idea how to make it work for all values?
reuploaded the file in the first post
note that this methode only works right for 0..1 values!
any body have an idea how to make it work for all values?
reuploaded the file in the first post
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: class array methodes expansion
ok looks that i found a working solution which works with all +/- combinations too..
i renamed the "set_to_range" methode to "scale_values" because i think the name makes mor clear what it does,
but the methode has 4 arguments now:
scale_values(newMin,newMax,oldMin,oldMax)
so you need to tell the methode also the old range but the old Range default is set to 0..1
so if this is the case (old range 0..1) only the new range is needed in the arguments!
some prooving would be appreciated
and i also found an easy implementation to use also the "<", ">", "<=", ">=" operators for array comparing
updated version in first post
i renamed the "set_to_range" methode to "scale_values" because i think the name makes mor clear what it does,
but the methode has 4 arguments now:
scale_values(newMin,newMax,oldMin,oldMax)
so you need to tell the methode also the old range but the old Range default is set to 0..1
so if this is the case (old range 0..1) only the new range is needed in the arguments!
some prooving would be appreciated
and i also found an easy implementation to use also the "<", ">", "<=", ">=" operators for array comparing
updated version in first post
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: class array methodes expansion
Couple of quick comments...
You don't need the 'random_order' method - there's already 'Array.shuffle' which does that.
I've done it myself loads of times; writing a load of code, and then seeing it right there the next time I look at the API doc's! He he - sometimes there's just too much Ruby!
For the scale_values, you can use the general form...
new_val = (old_val - old_min) * (new_max - new_min) / (old_max - old_min) + new_min
...that will work even for the 'reverse' situations, so you wont need all the 'abs' and 'if' methods.
For an even bigger speed boost, the maths can be re-factored and a couple of constant values pre-calculated...
That way the bit inside the loop loses the greedy divide and all the subtractions.
Keep up the good work - it's really nice to see some "Ruby toolkits" coming through!
You don't need the 'random_order' method - there's already 'Array.shuffle' which does that.
I've done it myself loads of times; writing a load of code, and then seeing it right there the next time I look at the API doc's! He he - sometimes there's just too much Ruby!
For the scale_values, you can use the general form...
new_val = (old_val - old_min) * (new_max - new_min) / (old_max - old_min) + new_min
...that will work even for the 'reverse' situations, so you wont need all the 'abs' and 'if' methods.
For an even bigger speed boost, the maths can be re-factored and a couple of constant values pre-calculated...
- Code: Select all
scale = (new_max - new_min) / (old_max - old_min)
offset = new_min - (old_min * scale)
new_array = old_array.map{|x| x * scale + offset}
That way the bit inside the loop loses the greedy divide and all the subtractions.
Keep up the good work - it's really nice to see some "Ruby toolkits" coming through!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: class array methodes expansion
trogluddite wrote:You don't need the 'random_order' method - there's already 'Array.shuffle' which does that.
I've done it myself loads of times; writing a load of code, and then seeing it right there the next time I look at the API doc's!
oh, yes thats cool! good that i postet the link to the api by myself not so bad in this case becaus i found the code in the web and put it in without asking myself a lot
trogluddite wrote:For the scale_values, you can use the general form...
new_val = (old_val - old_min) * (new_max - new_min) / (old_max - old_min) + new_min
...that will work even for the 'reverse' situations, so you wont need all the 'abs' and 'if' methods.
For an even bigger speed boost, the maths can be re-factored and a couple of constant values pre-calculated...
CODE: SELECT ALL
scale = (new_max - new_min) / (old_max - old_min)
offset = new_min - (old_min * scale)
new_array = old_array.map{|x| x * scale + offset}
That way the bit inside the loop loses the greedy divide and all the subtractions.
Keep up the good work - it's really nice to see some "Ruby toolkits" coming through!
great! thanks a lot for that, just dropped it in and also deleted the random_order..
updated version in first post
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: class array methodes expansion
after there are some troubles with FS Guru site i uploaded this one here in the forum again. last version in first post!
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 28 guests