Aliasing classes

S

Shak Shak

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
 
J

Jacob Mitchell

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top