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
Ruby Input Connector Names
7 posts
• Page 1 of 1
Ruby Input Connector Names
Hi Guys
Do any of you Ruby wizards know.. is it possible to parse the names of the input connectors to generate a hash as in the example below, a bit like map.with_index but map.with_names instead?
I hope this is self-explanatory!
Thanks in advance
Dave
Do any of you Ruby wizards know.. is it possible to parse the names of the input connectors to generate a hash as in the example below, a bit like map.with_index but map.with_names instead?
I hope this is self-explanatory!
Thanks in advance
Dave
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby Input Connector Names
Yes, it is. Ruby knows the symbol method to_sym.
"this".to_sym # :this
Be careful not to use it on dynamic data, because there is no garbage collection on such generated symbols! (You would create the famous "memory leak")
"this".to_sym # :this
Be careful not to use it on dynamic data, because there is no garbage collection on such generated symbols! (You would create the famous "memory leak")
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby Input Connector Names
Hi Tulamide
Thanks for the swift reply
perhaps I didn't explain very well
What I actually meant was can we 'extract' the names from the Ruby edit automatically.
In the example if I add another input, hash 'a' is automatically updated with the index but I want to use names for the keys not integers, doesn't matter if they are symbols or strings. Hash 'desired' is just an example of the result I'm after.
Hope this explains it better
Thanks for the swift reply
perhaps I didn't explain very well
What I actually meant was can we 'extract' the names from the Ruby edit automatically.
In the example if I add another input, hash 'a' is automatically updated with the index but I want to use names for the keys not integers, doesn't matter if they are symbols or strings. Hash 'desired' is just an example of the result I'm after.
Hope this explains it better
- Attachments
-
- Input Names.fsm
- (456 Bytes) Downloaded 886 times
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby Input Connector Names
Haven't downloaded the example yet, but based on your description I'd say it is possible, but more complicated. The only way I am aware of to get the name of the input as a string is via the RubyEditConnector class. This class is provided only in the event method. You'd basically have to trigger each input via
(or externally) and build the Hash one by one using the event method
I hope that helps you more?
- Code: Select all
input index, value
(or externally) and build the Hash one by one using the event method
- Code: Select all
def event i, v, t # i = RubyEditConnector, try i.to_s.to_sym or maybe even i.to_sym
end
I hope that helps you more?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby Input Connector Names
Hi Tulamide
I'm not sure I'm understanding you correctly, do you mean like this:
I'm relatively new to Ruby so please be gentle with me
Any chance you could post a simple example?
Thanks again
I'm not sure I'm understanding you correctly, do you mean like this:
I'm relatively new to Ruby so please be gentle with me
Any chance you could post a simple example?
Thanks again
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby Input Connector Names
Got it
After reading Trogg's excellent API Docs, should have looked there first
Thanks again anyway Tulamide, you pointed me in the right direction, very helpful as always
After reading Trogg's excellent API Docs, should have looked there first
Thanks again anyway Tulamide, you pointed me in the right direction, very helpful as always
- Attachments
-
- Input Names - Working.fsm
- (1.05 KiB) Downloaded 870 times
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby Input Connector Names
I was about to go out and didn't want to leave you without an answer. So I tried it from my head. And your final result looks exactly as I imagined it. I just forgot about the 'name' method, and I'm sorry for that. Luckily, you were able to help yourself. Well done!
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 75 guests