From: Josh Cheek Date: 2012-01-18T04:46:55+09:00 Subject: Re: Passing reference to a class --f46d041825cea0173204b6be964f Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jan 17, 2012 at 1: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 > > 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. --f46d041825cea0173204b6be964f--