If I can increment an integer:

x = 1
x += 2
x  #=> 3

... why doesn't it work the same inside a method?

gvim


On 12/06/2014 12:45, Juanjo Conti wrote:
> I guess that because in the second one c is a mutable object that is
> updated while in the first one is an inmutable one ovewriten.
>
> El jun 12, 2014 8:34 a.m., "gvim" <gvimrc / gmail.com
> <mailto:gvimrc / gmail.com>> escribi?:
>
>     Why do these accumulators behave differently?
>
>     def int_outer(a,b)
>        c = 0
>        def inner(aa,bb,cc)
>          cc += (aa + bb)
>        end
>        inner a, b, c
>        inner b, a, c
>        return c
>     end
>
>     p int_outer 3,4   #=> 0
>
>     def arr_outer(a,b)
>        c = []
>        def inner(aa,bb,cc)
>          cc << (aa + bb)
>        end
>        inner a, b, c
>        inner b, a, c
>        return c
>     end
>
>     p arr_outer 3,4  #=> [7,7]
>
>
>
>     gvim
>