summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-26 10:09:35 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-26 10:09:35 +0900
commit2856aa67df48409a1743b9126ff3bdc875ab2a98 (patch)
tree77c3cee1feafdbba534466bc0627e8f61b948e09 /doc
parent9269069e9056ba3ab74a885b68fc9d8c167f014d (diff)
[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.
Diffstat (limited to 'doc')
-rw-r--r--doc/syntax/literals.rdoc7
1 files changed, 7 insertions, 0 deletions
diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc
index 87a891bf2d..c876558d4e 100644
--- a/doc/syntax/literals.rdoc
+++ b/doc/syntax/literals.rdoc
@@ -547,6 +547,13 @@ with <tt>%w</tt> (non-interpolable) or <tt>%W</tt> (interpolable):
# (not nested array).
%w[foo[bar baz]qux] # => ["foo[bar", "baz]qux"]
+The interpolated string is treated as a single word even if it contains
+whitespace.
+
+ s = "bar baz"
+ %W[foo #{s} zot] #=> ["foo", "bar baz", "zot"]
+ %W[foo #{"bar baz zot"} qux] # => ["foo", "bar baz zot", "qux"]
+
The following characters are considered as white spaces to separate words:
* space, ASCII 20h (SPC)