Concatenation in Ruby Code

Hi -
Could someone please let me know how to concatenate a couple of strings in Ruby code over Logstash.
Below is the snippet of code:

for i in 0..arr.size - 1
cpu_hash = [cpu_hash, {'CPU#{i}' => arr[i].to_i}].reduce &:merge
end

Am creating a hash with the array of values. But I wanted to add the 'i' value in the key field along with the CPU word.
(So it creates unique key value)
In Ruby it works like this "CPU#{i}", not sure how does it work in Logstash. Please let me know. Thanks !

In Ruby it works like this “CPU#{i}”, not sure how does it work in Logstash.

It works exactly the same in Logstash, but the string needs to be double-quoted. Such string-interpolation doesn't take place in single-quoted strings like in your example.

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.