Search code examples
rubypass-by-referencefixnum

ruby and references. Working with fixnums


I know a bit about ruby way to handle objects and references. The replace stuff, ect ...

I know it d'ont work on fixnum, cause the var is the fixnum. But i wish to change the value of a fixnum inside a function, and that the value changed in the ouside var.

How can i do this ?

I guess i can use a string like this "1" but that's quite dirty.


Solution

  • You could pass an array with a single number, like [1], or a hash like {value: 1}. Less ugly than a string, as your number itself remains a number, but less overhead than a new class...