Print Variables in Ruby

1

How to print two variables on the same line (without jumping)? I've tried using print instead of puts but it did not work.

    
asked by anonymous 30.04.2016 / 18:09

3 answers

2

Use the concatenation character +

print variavel1 + " " + variavel2

or

You can use this way to interpret variables within a string as well:

print "Primeira variavel: #{variavel1} Segunda variavel: #{variavel2}"

or

You can pass as 2 parameters

print variavel1,variavel2
    
30.04.2016 / 18:14
1

For me it worked:

x = 1
y = 2
print x, y
print x
print y

See working on ideone .

    
30.04.2016 / 18:15
0

I used a gets.chomp and it worked.

    
30.04.2016 / 18:33