A Ruby Quirk
# $ denotes global variables in Ruby.
def function()
$number += 1;
$number += 2;
$number += 3;
return 4;
end
$number = 0;
$number += function();
Problem: What is in $number at the end of this code?
Answer (select to see): 4. the command at the end unfolds to '$number = $number + function()', then '$number = 0 + function()' before it executes function().
def function()
$number += 1;
$number += 2;
$number += 3;
return 4;
end
$number = 0;
$number += function();
Problem: What is in $number at the end of this code?
Answer (select to see): 4. the command at the end unfolds to '$number = $number + function()', then '$number = 0 + function()' before it executes function().
0 Comments:
Post a Comment
<< Home