# Linking Woes

**URL:** <https://www.ruby-forum.com/t/linking-woes/94144>\
**Category:** Ruby\
**Created:** [April 22, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/linking-woes/94144 "2006-04-22T19:50:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e9c0ed/32.png) [@wes](https://www.ruby-forum.com/u/wes)\
**Post date:** [April 22, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/linking-woes/94144/1 "2006-04-22T19:50:11Z")

</div>

test123.rb:3: uninitialized constant Profile (NameError)

This is the error message I am getting. I have written a class Profile  
which works just fine when I test it in Profile.rb. Whenever I go to  
link that class in a new file, though, I get the above error.

test123’s contents:

load “Profile.rb”  
t = Profile.new  
puts t.username

The latter two lines run perfectly well when after the Profile class  
definition in Profile.rb

Any advice?

---

<div class="post-metadata">

**Author:** ![wes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e9c0ed/32.png) [@wes](https://www.ruby-forum.com/u/wes)\
**Post date:** [April 22, 2006, 11:40pm UTC](https://www.ruby-forum.com/t/linking-woes/94144/2 "2006-04-22T23:40:13Z")

</div>

Wes wrote:

> puts t.username
> 
> The latter two lines run perfectly well when after the Profile class  
> definition in Profile.rb
> 
> Any advice?

Hi Wes,

It might be easier to help you if you let us see the entire contents of  
both files. Also, you might try testing it out in irb to see if that  
sheds any more light on the issue.

-Justin

---

<div class="post-metadata">

**Author:** ![wes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e9c0ed/32.png) [@wes](https://www.ruby-forum.com/u/wes)\
**Post date:** [April 23, 2006, 8:44am UTC](https://www.ruby-forum.com/t/linking-woes/94144/3 "2006-04-23T08:44:52Z")

</div>

Wes wrote:

> Here ya go

I made two files, copied what you posted, and it worked fine.  
Since the load command is working for you, the file is being loaded. Are  
you perhaps loading a different copy of the file? That’s all I can think  
of.  
You might try putting some command like

> puts “I loaded!”

somewhere in the Profile.rb file (maybe at the end) to make sure it’s  
actually being loaded.  
Another thing to try is running ruby with the -d option to check for  
less obvious problems.

On an unrelated topic, you can replace all the methods like

> def username= (username)  
> @username = username  
> end  
> with  
> attr\_accessor :username

Just like you used attr\_reader.

Hope that helps somewhat.

-Justin

---

<div class="post-metadata">

**Author:** ![wes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e9c0ed/32.png) [@wes](https://www.ruby-forum.com/u/wes)\
**Post date:** [April 23, 2006, 8:12am UTC](https://www.ruby-forum.com/t/linking-woes/94144/4 "2006-04-23T08:12:09Z")

</div>

Here ya go

Profile.rb

class Profile

attr\_reader :username, :height, :weight, :age, :activity\_level,  
:gender

@password #these field need never be read  
@meta\_calc\_strategy # The means of calculating metabolic rate

@@male\_gender = “Male”  
@@female\_gender = “Female”  
@@max\_activity\_level = 5  
#I have decided to implement a max\_activity\_level as I’ve noticed each  
#scale for metabolic rate has its own definition of how active a  
person can be.  
#When making a Strategy for calculating metabolic rate, dividing the  
#activity\_level / max\_activity\_level will give you a percentage that  
can be  
#used to place a person within any specific class.

def initialize  
puts 1  
end

def username= (username)  
@username = username  
end  
def password= (password)  
@password = password  
end  
def weight= (weight)  
@weight = weight  
end  
def height= (height)  
@height = height  
end  
def age= (age)  
@age = age  
end  
def activity\_level= (a\_l)  
@activity\_level = a\_l  
end  
def gender= (gender)  
@gender = gender  
end  
def meta\_calc\_strategy= (strategy)  
@meta\_calc\_strategy = strategy  
end

def get\_target\_calories  
@meta\_calc\_strategy.get\_target\_calories  
end

end

test123.rb

load “Profile.rb”

t = Profile.new  
puts t.username
