2

This doesn't work:

FOOBAR = 'foobar'
%W{ FOOBAR }

output: ["FOOBAR"]

However, the constant gets interpolated correctly by:

"#{FOOBAR}"
output: "foobar"
mcede
  • 117
  • 5
  • 2
    It's not just constants; try it with variables Think about it: `%w{...}` wouldn't be of much use if it tried to interpolate everything between the braces. – Cary Swoveland May 05 '15 at 12:40
  • Got it... You still need `#{ ... }` around the constant – mcede May 05 '15 at 13:00
  • what you want is [this](http://stackoverflow.com/a/690826/2767755) and [this](http://cyreath.blogspot.in/2014/05/ruby-w-vs-w-secrets-revealed.html). – Arup Rakshit May 05 '15 at 13:06
  • compare the output of: `%W{ FOOBAR #{FOOBAR} }` – DGM May 05 '15 at 13:56
  • What would be the use of a notation that interpolates every word? Wouldn't that just be the same as `[FOOBAR]`? – Max May 05 '15 at 15:22

1 Answers1

5

You're misusing %W literal. From book:

%W - Interpolated Array of words, separated by whitespace

so it doesn't have anything to do with interpolation.

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91