On 01/17/2012 01:36 PM, Tridib Bandopadhyay wrote:
> Hello
> 
> How to pass reference to a class in Ruby?
> 
> For example:-
> 
> def func(x)
>     x = x+1
> end
> 
> a = 5
> func(a)
> puts a

Instances of classes such as Fixnum, from your example, are immutable.
Your func method actually causes a new Fixnum instance to be created
whose value is 1 greater than the Fixnum instance passed in.

If you want to make a mutable number-like object that would work in your
example code, you'll need to create your own wrapper object that
implements all the necessary methods of the number object you wish to
emulate.  Take a look at the delegate library from the Ruby standard
library for something that might help you quickly whip up such a wrapper.

-Jeremy