mcede
mcede

Reputation: 117

Why doesn't interpolation of constants work with percent notation in Ruby

This doesn't work:

FOOBAR = 'foobar'
%W{ FOOBAR }

output: ["FOOBAR"]

However, the constant gets interpolated correctly by:

"#{FOOBAR}"
output: "foobar"

Upvotes: 2

Views: 688

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

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.

Upvotes: 5

Related Questions