MxyL MxyL - 1 year ago 115
Ruby Question

Ruby string substitution

Don't know what the term is called (substitution?), but in python if you type

num1 = 4
num2 = 2
print("Lucky numbers: %d %d" %(num1, num2))

You get "Lucky numbers: 4 2"

How do I do this in ruby?

Trying to do the above scenario, it works if I have one variable, but if I need to sub in multiple variables the parentheses aren't valid syntax.

Answer Source
num1 = 4  
num2 = 2  
print "Lucky numbers: %d %d" % [num1, num2]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download