From: Shak Shak on 30 Jun 2010 10:55 Hi all, Is it possible to alias a class? That is for ClassA.run to call ClassB.run instead? I have a third party library requiring a dependency which I've already defined with my own name. I'm currently subclassing, but I was wondering if there was a better way. Shak -- Posted via http://www.ruby-forum.com/.
From: Jacob Mitchell on 30 Jun 2010 12:21 [Note: parts of this message were removed to make it a legal post.] Yes, you simply set some variable equal to the name of a class and then in that scope it's a class alias. class A attr_accessor :x def initialize @x = 2 end end a = A.new puts a.x #=> 2 B = A b = B.new puts b.x #=> 2 puts b.class #=> A On Wed, Jun 30, 2010 at 10:55 AM, Shak Shak <sshaikh(a)hotmail.com> wrote: > Hi all, > > Is it possible to alias a class? That is for ClassA.run to call > ClassB.run instead? I have a third party library requiring a dependency > which I've already defined with my own name. I'm currently subclassing, > but I was wondering if there was a better way. > > Shak > -- > Posted via http://www.ruby-forum.com/. > >
|
Pages: 1 Prev: Networking: select() blocks for seconds (> timeout) Next: AUDIO FILE DOWNLOAD IN RUBY |