user2257812
user2257812

Reputation:

How to use variable inside %w{}

I want to use variable insite %w{} but this is generating only string.

I have try with

a="hello",
b="world"
%w{a b}

But this is display ["a", "b"] I want to display ["hello","world"]

Upvotes: 7

Views: 4346

Answers (1)

Paul.s
Paul.s

Reputation: 38728

If you want to use variables you can use interpolation and the %W variant

a = "hello"
b = "world"

pp %W{#{a} #{b} this is normal text} #=> ["hello", "world", "this", "is", "normal", "text"]

Upvotes: 18

Related Questions