On Tue, Jan 17, 2012 at 1:36 PM, Tridib Bandopadhyay <tridib04 / gmail.com>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
>
> Regards
>
> Tridib
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
Hi, it's not clear how this code example has anything to do with a
reference to a class (I assume you mean class as in Array, String, Object,
etc).

Anyway, classes are objects like anything else, they are accessed by
looking up the constants, but the constants are just references like
variables are, so you can do:


def instantiate(klass)
  klass.new
end

instantiate String # => ""
instantiate Array  # => []
instantiate Hash   # => {}


In this case, we name the variable "klass" because "class" is a keyword.