# Calling my framework

**URL:** <https://www.ruby-forum.com/t/calling-my-framework/120994>\
**Category:** Ruby\
**Created:** [November 22, 2007, 2:12pm UTC](https://www.ruby-forum.com/t/calling-my-framework/120994 "2007-11-22T14:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 22, 2007, 2:12pm UTC](https://www.ruby-forum.com/t/calling-my-framework/120994/1 "2007-11-22T14:12:18Z")

</div>

I’m developing a framework but I would like to call the classes as I was  
in Java.  
An example:  
requiere ‘myAclasses’  
requiere ‘myBclasses’  
vA=myclass22.new()  
vB=myclass55.new()

The problem is that I don’t know where are these classes and I would  
like to call them something like this:  
vA=myAclasses.myclass22.new()  
vB=myBclasses.myclass55.new()

Is this possible???  
How can I do it?

Thans in advance.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 23, 2007, 9:51am UTC](https://www.ruby-forum.com/t/calling-my-framework/120994/2 "2007-11-23T09:51:04Z")

</div>

On Nov 22, 2007 2:12 PM, Mario R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> vA=myAclasses.myclass22.new()  
> vB=myBclasses.myclass55.new()
> 
> Is this possible???  
> How can I do it?

Note that true class names has to start with an uppercase letter; I’ve  
compensated for that below.

First, you can do module wrapping (namespacing):

module MyAclasses  
class Myclass22  
end  
end

and call as  
MyAclasses::Myclass22.new

Second, you could do this using a method that returns a class object.

In other words, something like

class MyAClassContainer  
def myclass22  
return MyClass22  
end  
end  
myAclasses = MyAClassContainer.new # (or any other factory method)  
mya = myAclasses.myclass22.new

The latter technique can be useful if your hierarchy and what you want  
to produce change at runtime. It seems like very many levels of  
indirection, though, so I would think carefully of whether it is  
necessary. (Each level of indirection tends to make things harder to  
grasp/think about/debug.)

Eivind.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 23, 2007, 10:54am UTC](https://www.ruby-forum.com/t/calling-my-framework/120994/3 "2007-11-23T10:54:35Z")

</div>

The first seems to be the solution to my problem, I didn’t realize  
before.  
Even you can add more modules:  
module Mod1  
module Mod2  
class Clas1  
end Class  
end  
end

a=Mod1::Mod2::Clas1.new()

That’s great!!!

Thank you very much.
