variables a, b, c and d all need to be set to 'foo'.
Is there a way to accomplish this in one swooping assignment? Like:
a, b, c, d = 'foo'
variables a, b, c and d all need to be set to 'foo'.
Is there a way to accomplish this in one swooping assignment? Like:
a, b, c, d = 'foo'
Ref [this][1]
Best way to do it as follow as you need common value to all your variables
a= b= c = d = 'foo'
for different value you can do
a, b, c, d = 'foo1', 'foo2', 'foo3', 'foo4'
I believe Ruby supports the normal type of chained assignment, like:
a = b = c = d = 'foo'
a = b = c = d = 'foo'
is surely the correct way to do it... If you want a bit a freaky way:
a,b,c,d = %w{foo}*4
(%w{foo} returns a string array containing foo, *4 multiplies this array so you get an array containing 4 times the string foo and you can assign an array to multiple comma-separated variable names)