curriculum
curriculum copied to clipboard
Pattern Matching lesson (Ruby) - Incorrect info about return statement
Inside of the Pattern Matching lesson, in the paragraph about the return values of a Pattern Matching statement, this is said:
Return values
There are two possible return values from a pattern match statement. The first is
true
which is returned whenever there is a match, even when the match is the else clause in a statement. The second possible return value is aNoMatchingPatternError
whenever no match can be found.
While the second statement is true (when there is no pattern that matches and no else guard, a NoMatchingPatternError is raised), the first one is wrong. When there is a match with a pattern, the return value of the Pattern Matching statement is the last evaluated value inside of the matched-pattern body. If the body is empty, then the return value is nil. When there is no match, but the else guard is present, the return value of the statement is the last evaluated value inside of the else body. If the body is empty, then the return value is nil.
True is not the default value for a Pattern Matching Statement.