Skip to content

Commit 2856aa6

Browse files
committed
[DOC] State that an interpolated string in %W is not split
It is split statically at the parse time, not the whole string is built then split.
1 parent 9269069 commit 2856aa6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

doc/syntax/literals.rdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ with <tt>%w</tt> (non-interpolable) or <tt>%W</tt> (interpolable):
547547
# (not nested array).
548548
%w[foo[bar baz]qux] # => ["foo[bar", "baz]qux"]
549549

550+
The interpolated string is treated as a single word even if it contains
551+
whitespace.
552+
553+
s = "bar baz"
554+
%W[foo #{s} zot] #=> ["foo", "bar baz", "zot"]
555+
%W[foo #{"bar baz zot"} qux] # => ["foo", "bar baz zot", "qux"]
556+
550557
The following characters are considered as white spaces to separate words:
551558

552559
* space, ASCII 20h (SPC)

0 commit comments

Comments
 (0)