Reputation: 5952
Starting from and array of numbers such as
a = [1,2,3]
I need to get the following string
"values in (1,2,3)"
If I try a simple interpolation
"values in (#{a})" => "values in ([1,2,3])"
I could use gsub to remove [ and ] but I'd rather find a cleaner way. Any suggestions?
Thanks
Upvotes: 1
Views: 140
Reputation: 13911
An alternative:
a, bracs = [1,2,3], %w{[] ()}
p "values in #{a}".tr(*bracs) #=> "values in (1, 2, 3)"
Upvotes: 0
Reputation: 118271
Here is one more :
a = [1,2,3]
p "values in (#{a* ","})" # => "values in (1,2,3)"
Upvotes: 1