# Ruby snippet to iterate through array results in error "Ruby exception occurred: undefined method \`\[\]' for #\<LogStash::Event:0x69068bc1\>\`"

**URL:** https://discuss.elastic.co/t/ruby-snippet-to-iterate-through-array-results-in-error-ruby-exception-occurred-undefined-method-for-logstash-0x69068bc1/222166
**Category:** Logstash
**Created:** [March 4, 2020, 10:07pm UTC](https://discuss.elastic.co/t/ruby-snippet-to-iterate-through-array-results-in-error-ruby-exception-occurred-undefined-method-for-logstash-0x69068bc1/222166 "2020-03-04T22:07:24Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [March 5, 2020, 12:42am UTC](https://discuss.elastic.co/t/ruby-snippet-to-iterate-through-array-results-in-error-ruby-exception-occurred-undefined-method-for-logstash-0x69068bc1/222166/4 "2020-03-05T00:42:22Z")

</div>

> [@kaj](#):
>
> event.set("parameter\_%{index}", "value")

That's not how you do string interpolation in ruby. sprintf references are a logstash thing, not a ruby thing. Try

```
event.set("parameter_#{index}", value)

```

As a point of style I think it would be more common to do

```
ids = event.get("parameter")
if ids
    ...

```

thus getting rid of the intermediate variable.

---

_[View the full topic](https://discuss.elastic.co/t/ruby-snippet-to-iterate-through-array-results-in-error-ruby-exception-occurred-undefined-method-for-logstash-0x69068bc1/222166)._
