From ca2170e69f454259c612143a8c3bf6ab576d7f4d Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Mon, 3 Jun 2024 12:24:55 +0900 Subject: [DOC] percent literals can be nested. --- doc/syntax/literals.rdoc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'doc/syntax') diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc index 0c1e4a434b..01df0c09b8 100644 --- a/doc/syntax/literals.rdoc +++ b/doc/syntax/literals.rdoc @@ -453,6 +453,8 @@ may use these paired delimiters: * < and >. * Any other character, as both beginning and ending delimiters. +The first four pairs (brackets, parenthesis, braces, and angle brackets) can be nested. + These are demonstrated in the next section. === %q: Non-Interpolable String Literals @@ -467,6 +469,10 @@ The created string is the same as if you created it with single quotes: %|foo bar baz| # => "foo bar baz" # Using two |. %:foo bar baz: # => "foo bar baz" # Using two :. %q(1 + 1 is #{1 + 1}) # => "1 + 1 is \#{1 + 1}" # No interpolation. + %q[foo[bar]baz] # => "foo[bar]baz" # brackets can be nested. + %q(foo(bar)baz) # => "foo(bar)baz" # parenthesis can be nested. + %q{foo{bar}baz} # => "foo[bar]baz" # braces can be nested. + %qbaz> # => "foo[bar]baz" # angle brackets can be nested. === % and %Q: Interpolable String Literals @@ -488,6 +494,10 @@ or %W (interpolable): %w(#{1 + 1}) # => ["\#{1", "+", "1}"] %W(#{1 + 1}) # => ["2"] + # The nested delimiters evaluated to a flat array of strings + # (not nested array). + %w[foo[bar baz]qux] # => ["foo[bar", "baz]qux"] + === %i and %I: Symbol-Array Literals You can write an array of symbols with %i (non-interpolable) -- cgit v1.2.3