How to add few statements in one Ruby command?

For general discussion related FlowStone
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: How to add few statements in one Ruby command?

Post by tulamide »

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?
"There lies the dog buried" (German saying translated literally)
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: How to add few statements in one Ruby command?

Post by Tronic »

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.
Post Reply