I have a the following
Class Usertype
def add(a,b)
return a + b
end
end
and another class called Profession.
Class Profession
def users
end
end
What I want to be able to do is,in profession object, add a method
called “users”(shown above) which will return an instance of that
usertype util object?
Then if p1 = Usertype.new
I should be able to access add by using p1.users.add(a,b)
Is this possible?
Namrata K. wrote in post #1039581:
What I want to be able to do is,in profession object, add a method
called “users”(shown above) which will return an instance of that
usertype util object?
Then if p1 = Usertype.new
I should be able to access add by using p1.users.add(a,b)
Is this possible?
I think you mean if p1 = Profession.new
Then in that case all you need is:
class Profession
def users
Usertype.new
end
end
In this case it’s not very useful. However when the throw-away object
also carries some state from its creator, then it can be very useful.
Yes, I meant p1 = Profession.new
and I defined users with a return type and it worked.
Thanks.