Elementary Question on Variables

hey all,

this is a great community and I'm glad I found it...also, this is my
first post.

In the code example below taken from Chris Pine Learn to Program RoR
book, I'm curious why there is (what looks like to me) a hanging
variable: "size". It is the third line from the bottom. I understand
how recursion is working here, but I'm not sure why "size" is just
sitting there at the bottom. I removed the line and re-ran the program
and still got the correct result. Am I missing something?

hey all,

this is a great community and I'm glad I found it...also, this is my
first post.

In the code example below taken from Chris Pine Learn to Program RoR
book, I'm curious why there is (what looks like to me) a hanging
variable: "size". It is the third line from the bottom. I understand
how recursion is working here, but I'm not sure why "size" is just
sitting there at the bottom. I removed the line and re-ran the
program
and still got the correct result. Am I missing something?

The return value of method in ruby is the result of the last statement
(or whatever you pass to return)
Sticking size at the bottom of that method makes that the result. If
you remove that then the return value will be the previous statement
ie size = size + continent_size(world, x+1, y+1)

which will generate the same return value, however the intention is
not perhaps as explicit as if you have size on its own at the end of
the method.

Fred

Thanks Fred, your comments were very helpful.