Jimeh
Jimeh

Reputation: 397

Dynamic parameters using variable as key

Lets say I have a method foo:

def foo(options = {})
  ...
end

I want to pass a variable as the key.

fooKey = "option1"
foo(fooKey: "bar1", option2: 'bar2')

Is this possible?

Upvotes: 0

Views: 68

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

Just use the hashrocket syntax

foo(fooKey => 'bar1', :option2 => 'bar2')

Upvotes: 3

Related Questions