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
How to add few statements in one Ruby command?
12 posts
• Page 2 of 2 • 1, 2
Re: How to add few statements in one Ruby command?
Tronic, I know it is just an example, but for those who don't have that much experience with programming I want to point out that the second "when" will never be executed and the first one will not notice equality.
theTittle and theTattle are or'ed (using the pipe sign "|"). That means both arrays will be looked up for a valid object. If the Tattle contains the number 5 and input is also 5 then the first "when" becomes true and its code will be executed. Then the "case" structure is left, whatever follows is not of interest anymore. That's how it is designed. So in this case, although the condition for the second "when" is true, it will never be executed.
Say, theTittle and theTattle both contain the number 5. Or'ing the arrays means, whatever value is 5 will result to true. Which also means you can't differentiate which one matches the input 5. The only thing you know is that there is at least one value 5, but it might also be two, three or even the whole arrays.
Hope this explains it?
theTittle and theTattle are or'ed (using the pipe sign "|"). That means both arrays will be looked up for a valid object. If the Tattle contains the number 5 and input is also 5 then the first "when" becomes true and its code will be executed. Then the "case" structure is left, whatever follows is not of interest anymore. That's how it is designed. So in this case, although the condition for the second "when" is true, it will never be executed.
Say, theTittle and theTattle both contain the number 5. Or'ing the arrays means, whatever value is 5 will result to true. Which also means you can't differentiate which one matches the input 5. The only thing you know is that there is at least one value 5, but it might also be two, three or even the whole arrays.
Hope this explains it?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: How to add few statements in one Ruby command?
Oh sure, this example is based on the fact that the two arrays of values do not contain equal values,
otherwise the behavior would be incorrect.
It works like exclusively match, and its operation is specific to a few cases.
otherwise the behavior would be incorrect.
It works like exclusively match, and its operation is specific to a few cases.
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
12 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 55 guests