[{"id":"rubyadvanced-001","courseId":"ruby-advanced","domain":"syntax-and-literals","topic":"Standalone => and in matching","prompt":"Ruby's docs give the template of a case / in expression with an else branch. Put these four parts in the order that template writes them.","hint":"Think about what the construct needs before it can list any branches.","explain":"A multi-way match is a block built from four kinds of part: an opening that names the inspected value, shape tests, an optional last resort, and a required closing. Each kind has a job that fixes its place.","source":"https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html","interaction":{"type":"sort","items":[{"text":"case <expression>","why":"The value being inspected is named before any branch is written."},{"text":"in <pattern1>","why":"Branches come after the subject, and each one is introduced by the in keyword."},{"text":"else","why":"The optional fallback comes after the branches it catches."},{"text":"end","why":"The whole construct is closed last, after every branch and the fallback."}]},"options":[],"answer":"o:abcd","explanation":"A case / in expression is written as case <expression>, then one or more in <pattern> branches, an optional else, and a closing end.","concept":"A case / in expression is written as case <expression>, then one or more in <pattern> branches, an optional else, and a closing end.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["The case / in layout has a subject, one or more branches, an optional else, and a closing end."]},{"id":"rubyadvanced-002","courseId":"ruby-advanced","domain":"syntax-and-literals","topic":"NoMatchingPatternError without else","prompt":"A teammate writes this case / in with no else branch. A response with status 500 reaches it. What happens?","hint":"Consider what happens to a value no branch covers when there is no else.","explain":"A case block checks a value's shape against its branches. A fallback clause is optional, and what happens to a value that fits no branch depends on whether one exists.","source":"https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Ruby raises NoMatchingPatternError","why":"A case / in with no matching branch and no else is exhaustive, so an unmatched value raises this error."},{"id":"b","text":"The case returns nil","whyNot":"That is how a case / when with no match behaves; case / in with no else raises an error instead."},{"id":"c","text":"The 500 matches the first branch with body set to nil","whyNot":"The hash pattern requires status to be 200, so a 500 never fits the first branch."},{"id":"d","text":"Ruby raises KeyError because no branch names 500","whyNot":"Pattern matching does not look up keys like a hash fetch; the failure is NoMatchingPatternError."}],"answer":"a","explanation":"A case / in expression is exhaustive: if no branch matches and there is no else, Ruby raises NoMatchingPatternError.","concept":"A case / in expression is exhaustive: if no branch matches and there is no else, Ruby raises NoMatchingPatternError.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"case response\nin { status: 200, body: }\n  body\nin { status: 404 }\n  nil\nend","takeaways":["Without an else, an unmatched case / in value is an error, not nil; add an else when a miss is expected."]},{"id":"rubyadvanced-003","courseId":"ruby-advanced","domain":"syntax-and-literals","topic":"Find patterns","prompt":"A teammate claims: the find pattern in [*, String, String, *] matches an array only when that array holds exactly two Strings. Judge the claim.","hint":"Ask what the splats at each end are allowed to absorb.","explain":"A find pattern searches an array for a stretch of elements that fits its inner subpatterns. The splats at each end describe what may surround that stretch.","source":"https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"A find pattern only needs some run of elements to fit; the docs' example matches an array holding three Strings."},{"id":"b","text":"False","why":"The splats let other elements sit around the matched run, so the array in the docs matches even with three Strings."}],"answer":"b","explanation":"A find pattern checks whether an array has any elements matching its subpatterns; the splats at each end absorb the rest, so extra matching elements are allowed.","concept":"A find pattern checks whether an array has any elements matching its subpatterns; the splats at each end absorb the rest, so extra matching elements are allowed.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A find pattern asks whether a matching run exists anywhere in the array, not whether the array has exactly that many matches."]},{"id":"rubyadvanced-004","courseId":"ruby-advanced","domain":"syntax-and-literals","topic":"Pin operator in patterns","prompt":"Which TWO statements about the pin operator in Ruby pattern matching are correct?","hint":"Compare what a bare name does inside a pattern with what the marker changes.","explain":"A bare name in a pattern captures whatever it meets and overwrites that variable. Sometimes you want a comparison instead, so check which notations in a pattern make Ruby compare rather than capture.","source":"https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A pin like ^expectation matches the existing value of expectation instead of binding a new variable.","why":"The caret makes the pattern compare against the current value rather than capture into a new local."},{"id":"b","text":"The caret can take a parenthesized expression, such as ^(a + b), and matches against its result.","why":"The docs pin the result of an arbitrary expression written in parentheses, so ^(a + b) matches the sum."},{"id":"c","text":"A bare name like expectation in a pattern compares against the variable's current value.","whyNot":"A bare name captures: it rewrites the variable with the matched element, which is the problem pins solve."},{"id":"d","text":"The caret works only on local variables, never on instance, class or global variables.","whyNot":"Instance, global and class variables can all be pinned, as the docs show."},{"id":"e","text":"A class name like Integer needs a caret before it, or it is read as a new variable.","whyNot":"A constant such as Integer is already a value pattern, matched with ===, so no caret is needed."},{"id":"f","text":"Pinning makes the match rebind the variable to the matched element, so later code sees the new value.","whyNot":"A pin only compares; it never rebinds the variable it names."}],"answer":"ab","explanation":"A bare name in a pattern binds; the pin operator ^ makes the pattern compare against an existing local, instance, global or class variable, or a parenthesized expression's result.","concept":"A bare name in a pattern binds; the pin operator ^ makes the pattern compare against an existing local, instance, global or class variable, or a parenthesized expression's result.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"expectation = 18\ncase [1, 2]\nin ^expectation, *rest\n  :matched\nelse\n  :missed\nend","takeaways":["Inside a pattern, a bare name captures; a caret-marked name or parenthesized expression is compared instead."]},{"id":"rubyadvanced-005","courseId":"ruby-advanced","domain":"syntax-and-literals","topic":"Guard clauses in patterns","prompt":"A teammate wants a match that counts only when the second element is twice the first. Which form lets the guard attach to the pattern?","hint":"Only one of these places allows the condition right after the pattern.","explain":"A pattern can be followed by an extra condition the matched values must also meet. Not every way of writing a pattern accepts one, and where one is refused, a trailing keyword means something else.","source":"https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html","interaction":{"type":"single"},"options":[{"id":"a","text":"A case / in branch written: in a, b if b == a * 2","why":"A guard follows the pattern inside a case / in branch, and the if attaches the condition to that branch."},{"id":"b","text":"pair => a, b if b == a * 2","whyNot":"The arrow form cannot take a guard; the trailing if becomes a modifier on the whole statement."},{"id":"c","text":"pair in a, b if b == a * 2","whyNot":"A standalone in cannot take a guard either, so the trailing if is only a modifier on that statement."},{"id":"d","text":"A case / in branch written: in a, b and b == a * 2","whyNot":"A guard is introduced by if or unless after the pattern; a logical operator is not a guard keyword."}],"answer":"a","explanation":"A guard follows the pattern in a case / in branch and uses if or unless; => and standalone in cannot take one, so a trailing if there is a modifier on the whole statement.","concept":"A guard follows the pattern in a case / in branch and uses if or unless; => and standalone in cannot take one, so a trailing if there is a modifier on the whole statement.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Guards belong to case / in branches; => and standalone in take a trailing if only as a plain modifier."]}]