# Concatenation in Ruby Code

**URL:** <https://discuss.elastic.co/t/concatenation-in-ruby-code/99614>\
**Category:** Logstash\
**Created:** [September 6, 2017, 5:05pm UTC](https://discuss.elastic.co/t/concatenation-in-ruby-code/99614 "2017-09-06T17:05:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul1243](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@paul1243](https://discuss.elastic.co/u/paul1243)\
**Post date:** [September 6, 2017, 5:05pm UTC](https://discuss.elastic.co/t/concatenation-in-ruby-code/99614/1 "2017-09-06T17:05:17Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 7, 2017, 5:29am UTC](https://discuss.elastic.co/t/concatenation-in-ruby-code/99614/2 "2017-09-07T05:29:55Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 5, 2017, 5:30am UTC](https://discuss.elastic.co/t/concatenation-in-ruby-code/99614/3 "2017-10-05T05:30:11Z")

</div>

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