+ 2

Capital letter

why can't variable names begin with a capital letter?

15th Dec 2016, 4:23 PM
Ioanna Zapalidi
3 odpowiedzi
+ 7
Variables that start with a capital letter are automatically constants, e.g. The following code will be executed successfully: x = 8 puts x #prints 8 x = 28 puts x #prints 28 But the following code causes warnings: Ax = 8 puts Ax #prints 8 Ax = 28 #warning: already initialized constant Ax puts Ax #prints 28, but displays a warning Despite the fact that Ruby does not prohibit changing the constants, it is bad practice.
15th Dec 2016, 9:46 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
+ 3
good answer!
31st Dec 2016, 5:25 PM
Ahmed Albayoumy
Ahmed Albayoumy - avatar
0
declaring variables by capital format leads to constants.
18th Feb 2017, 7:30 AM
Chaitanya
Chaitanya - avatar