[{"id":"rubyintermediate-001","courseId":"ruby-intermediate","domain":"syntax-and-literals","topic":"Percent-w string arrays","prompt":"A teammate needs an array of three color names and wants to skip typing quotes and commas. They write colors = %w[red green blue]. What is colors?","hint":"Look at the letter that follows the percent sign.","explain":"Ruby has short literal forms that build a collection from a run of words. Each starts with a percent sign and a letter, and the letter decides what kind of items you get.","source":"https://docs.ruby-lang.org/en/master/doc/syntax/literals_rdoc.html","interaction":{"type":"single"},"options":[{"id":"a","text":"An array of three strings: \"red\", \"green\", \"blue\"","why":"%w builds an array of strings from the whitespace-separated words between its delimiters."},{"id":"b","text":"An array of three symbols: :red, :green, :blue","whyNot":"Symbols come from %i, not %w; %w gives strings."},{"id":"c","text":"One string: \"red green blue\"","whyNot":"The words are split on whitespace, so %w does not produce one string."},{"id":"d","text":"A SyntaxError, because the words need commas","whyNot":"Words in %w are separated by whitespace, so no commas are needed."}],"answer":"a","explanation":"%w writes an array of strings as whitespace-separated words, with no quotes or commas needed. %i is the matching form for arrays of symbols.","concept":"%w writes an array of strings as whitespace-separated words, with no quotes or commas needed. %i is the matching form for arrays of symbols.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["%w builds an array of strings from words; %i builds an array of symbols."]},{"id":"rubyintermediate-002","courseId":"ruby-intermediate","domain":"syntax-and-literals","topic":"Adjacent string literals","prompt":"In Ruby, two string literals written side by side in the source, as in \"Hello, \" \"world\", join into one string without an operator between them.","hint":"Think about what the parser does with quoted text that sits next to other quoted text.","explain":"Some literals written next to each other in source get special handling from the parser. Consider what the parser does with a gap between two quoted pieces of text, and whether it needs an operator there.","source":"https://docs.ruby-lang.org/en/master/doc/syntax/literals_rdoc.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The interpreter concatenates adjacent string literals automatically, so no + is needed."},{"id":"b","text":"False","whyNot":"Side-by-side string literals are joined automatically; a + operator is not required."}],"answer":"a","explanation":"Adjacent string literals are concatenated by the interpreter. The rule covers single-quote, double-quote and percent strings, as long as a percent string is not last.","concept":"Adjacent string literals are concatenated by the interpreter. The rule covers single-quote, double-quote and percent strings, as long as a percent string is not last.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Adjacent string literals join automatically; reach for + only when the pieces come from variables."]},{"id":"rubyintermediate-003","courseId":"ruby-intermediate","domain":"syntax-and-literals","topic":"Interpolated value inside a percent word array","prompt":"A script sets s = \"bar baz\", then writes tags = %W[ foo #{ s } zot ]. What does tags hold?","hint":"Whitespace separates words in the literal text. Ask whether a value brought in by #{ } is split the same way.","explain":"Percent word-array literals split their text into elements at whitespace. Think about whether that splitting applies to a value a placeholder inserts, and how many elements that value makes.","source":"https://docs.ruby-lang.org/en/master/doc/syntax/literals_rdoc.html","interaction":{"type":"single"},"options":[{"id":"a","text":"[\"foo\", \"bar baz\", \"zot\"]","why":"%W fills the placeholder, and the interpolated text stays one element even though it contains a space."},{"id":"b","text":"[\"foo\", \"bar\", \"baz\", \"zot\"]","whyNot":"Whitespace splits the literal words, but a value filled in by #{ } stays one element."},{"id":"c","text":"[\"foo\", \"#{ s }\", \"zot\"]","whyNot":"%W fills the placeholder in, so the element is the value of s, not the literal text #{ s }."},{"id":"d","text":"A SyntaxError, because a placeholder cannot sit between two words","whyNot":"A placeholder may sit between plain words in %W; the literal is valid and runs."}],"answer":"a","explanation":"%W fills #{} placeholders inside its words, and an interpolated value stays one element of the array even when it contains whitespace.","concept":"%W fills #{} placeholders inside its words, and an interpolated value stays one element of the array even when it contains whitespace.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["%W fills #{} placeholders; an interpolated value stays one element, even when it contains spaces."]},{"id":"rubyintermediate-004","courseId":"ruby-intermediate","domain":"syntax-and-literals","topic":"Symbol-array literals","prompt":"A developer chooses between the %i and %I literals for a list of status symbols. Which TWO statements about these literals are true?","hint":"Compare the lowercase and uppercase forms, and how the words are separated.","explain":"Some literal forms build arrays from a run of words. The letter after the percent sign decides what the items are and whether they can contain a placeholder.","source":"https://docs.ruby-lang.org/en/master/doc/syntax/literals_rdoc.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"%i writes an array of symbols from whitespace-separated words.","why":"The %i literal takes whitespace-separated words and builds an array of symbols."},{"id":"b","text":"%I is the interpolable form, so #{} works inside its words.","why":"%I allows interpolation; %i is non-interpolable."},{"id":"c","text":"Words in %i must be separated by commas.","whyNot":"Words are separated by whitespace, so commas are not used between them."},{"id":"d","text":"%i runs #{} interpolation inside each of its words.","whyNot":"%i is non-interpolable; the uppercase %I is the form that interpolates."},{"id":"e","text":"%I builds an array of strings, not symbols.","whyNot":"Both forms build arrays of symbols; the uppercase letter only adds interpolation."},{"id":"f","text":"A space inside %i always ends the symbol, and no escape can keep it.","whyNot":"A backslash-escaped space stays part of the word, as it does in %w."}],"answer":"ab","explanation":"%i and %I write arrays of symbols from whitespace-separated words. %I allows interpolation, and an escaped space stays inside its word.","concept":"%i and %I write arrays of symbols from whitespace-separated words. %I allows interpolation, and an escaped space stays inside its word.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Use %i for fixed symbol lists and %I when the words need interpolation."]},{"id":"rubyintermediate-005","courseId":"ruby-intermediate","domain":"syntax-and-literals","topic":"Splat on the left of a multiple assignment","prompt":"A method returns a list, and the code reads: first, *middle, last = list. Which TWO statements about the * on the left-hand side are true?","hint":"Think about where the starred name may sit, and how many starred names one assignment may contain.","explain":"A multiple assignment can gather leftover values into one name by marking it with an asterisk. Think about how many such names an assignment may have, and where on the left side they may stand.","source":"https://docs.ruby-lang.org/en/master/doc/syntax/assignment_rdoc.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The * may stand anywhere on the left-hand side, at the start, middle or end.","why":"The * can appear anywhere on the left-hand side, so it need not be the last name."},{"id":"b","text":"An assignment may contain only one * on its left-hand side.","why":"Only one * is allowed in an assignment, however the names are arranged."},{"id":"c","text":"Two * names are allowed when a comma separates them.","whyNot":"Only one * is allowed in an assignment, even with a comma between the names."},{"id":"d","text":"The * must always be the last name on the left-hand side.","whyNot":"The * can appear anywhere on the left, as in first, *middle, last."},{"id":"e","text":"Any assignment with a * on the left is a SyntaxError.","whyNot":"A * on the left is valid multiple assignment syntax, so it is not an error by itself."},{"id":"f","text":"The starred name must be the only name on the left-hand side.","whyNot":"Other names can sit beside the starred one, as in first, *middle, last."}],"answer":"ab","explanation":"In multiple assignment, one name on the left may be starred. The star can sit anywhere on the left, but an assignment may use only one.","concept":"In multiple assignment, one name on the left may be starred. The star can sit anywhere on the left, but an assignment may use only one.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Use one starred name per assignment; it may sit at the start, middle or end of the left side."]}]