+ 2

What happens if I assign a variable x to 8, and Y to x, can i later change what value x holds? Or is Y forced to be equal to 8?

Hopefully the question is clear enough.

2nd Jun 2017, 9:40 AM
william
4 odpowiedzi
+ 12
Yes, you can change the value whenever you want. x = 8 y = x y = 10 puts x # 8 puts y # 10
2nd Jun 2017, 9:44 AM
Maz
Maz - avatar
+ 10
And what would be the difference? Ruby is case sensitive, but if you write "Y" instead of "y" you will have the same output in this case. :3
2nd Jun 2017, 9:53 AM
Maz
Maz - avatar
+ 1
firstly you can't assign a variable to any constant, reverse though! now x= 8; y=x x=9; see you can change the value assigned to x, but y has the same value of x previously assigned i.e 8 if you print the vars, you get x=9 y=8
2nd Jun 2017, 9:56 AM
Aman Kumar
Aman Kumar - avatar
0
I'm saying if Y is capitalized
2nd Jun 2017, 9:49 AM
william