# Uninitialized constant Connector(Name Error)

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846>\
**Category:** Ruby\
**Created:** [September 12, 2010, 7:11am UTC](https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846 "2010-09-12T07:11:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thotheolh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@thotheolh](https://www.ruby-forum.com/u/thotheolh)\
**Post date:** [September 12, 2010, 7:11am UTC](https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846/1 "2010-09-12T07:11:34Z")

</div>

I have seen a thread that has nearly the same problems but I guess mine  
should be some other problems.

I had my Connector.rb and test.rb classes next to each other so it  
should be able to interact.

Do bear with me as I am very new to ruby. I just started to experiment  
abit with ruby lately.

---

<div class="post-metadata">

**Author:** ![thotheolh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@thotheolh](https://www.ruby-forum.com/u/thotheolh)\
**Post date:** [September 13, 2010, 3:19am UTC](https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846/2 "2010-09-13T03:19:57Z")

</div>

Is this problem really that uncommon ?

Tay Thotheolh wrote:

> I have seen a thread that has nearly the same problems but I guess mine  
> should be some other problems.
> 
> I had my Connector.rb and test.rb classes next to each other so it  
> should be able to interact.
> 
> Do bear with me as I am very new to ruby. I just started to experiment  
> abit with ruby lately.

---

<div class="post-metadata">

**Author:** ![thotheolh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@thotheolh](https://www.ruby-forum.com/u/thotheolh)\
**Post date:** [September 13, 2010, 8:44am UTC](https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846/3 "2010-09-13T08:44:04Z")

</div>

Hi Collins. Thanks for the reply. Would look into it.

> file (in a Java-ish) way

I came from a Java background where my idea was you just call Connector  
like in Java and it should be loaded. This is my first attempt of really  
sitting down and creating a ruby program by trial and error and learning  
along the way.

---

<div class="post-metadata">

**Author:** ![thotheolh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@thotheolh](https://www.ruby-forum.com/u/thotheolh)\
**Post date:** [September 13, 2010, 6:00am UTC](https://www.ruby-forum.com/t/uninitialized-constant-connector-name-error/194846/4 "2010-09-13T06:00:30Z")

</div>

On 09/12/2010 06:20 PM, Tay Thotheolh wrote:

> > Do bear with me as I am very new to ruby. I just started to experiment  
> > abit with ruby lately.

Hi Tay,

For future questions, please describe the results you are trying to  
achieve and how what you see differs from what you want. Include error  
messages if they exist. If your code is not too long (and in this case  
it really isn’t) it is easier for people to help if it is directly  
included in your email.

It appears that you are expecting Ruby to “know” that the Connector  
class (really the Connector constant) is defined in the Connector.rb  
file (in a Java-ish) way. That’s not how Ruby works. You need to  
explicitly “load” or “require” a file. For example, add

require “connector” #if you are using Ruby 1.8

or

require\_relative “connector” #if you are using 1.9.2

to the top of your test.rb file.

However, you will quickly find that you get a new error. Something like:

test.rb:13:in `dotest': undefined method`new’ for Connector:Module  
(NoMethodError)  
from test.rb:28:in `’

I think you want Connector to be a class, not a module. Modules are not  
instantiated as instances, only classes are.

Okay. Now your code will likely work, but there are still some issues.  
In Connector.rb (by the way, the convention would be to have the file  
name lower-cased), you have this:

#Globals  
@hostname;  
@port;  
@soc;

First of all, conventionally semicolons are only used when you want  
multiple expressions sharing the same line. They are completely  
redundant here.

Secondly, these are not really globals. Globals begin with a dollar sign  
($). But why even bother? You do not use these as globals. You can get  
rid of these lines completely.

Here’s some more code:

def send(message) # send tcp messages  
@soc.puts(message);  
return @soc.gets;  
end

Methods in Ruby return the last value by default, so “return” here is  
not needed.

And some more:

def close()

```
 if(!(@soc.closed?)==true)
   @soc.close
 end

```

end

A more idiomatic way to write this would be:

def close

```
 @soc.close unless @soc.closed?

```

end

And for this:

def is\_closed()  
return @soc.closed?  
end

The Rubyish way would be:

def closed?  
@soc.closed?  
end

Hope that helps.

-Justin
