Forum: Ruby Linking Woes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4cc03e742e776c7e4162cc88001dbe7e?d=identicon&s=25 Wes (Guest)
on 2006-04-22 19:50
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 =
puts t.username

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

Any advice?
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-04-22 23:40
(Received via mailing list)
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.

4cc03e742e776c7e4162cc88001dbe7e?d=identicon&s=25 Wes (Guest)
on 2006-04-23 08:12
Here ya go


class Profile

  attr_reader :username, :height, :weight, :age, :activity_level,

  @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

  def username= (username)
    @username = username
  def password= (password)
    @password = password
  def weight= (weight)
    @weight = weight
  def height= (height)
    @height = height
  def age= (age)
    @age = age
  def activity_level= (a_l)
    @activity_level = a_l
  def gender= (gender)
    @gender = gender
  def meta_calc_strategy= (strategy)
    @meta_calc_strategy = strategy

  def get_target_calories



load "Profile.rb"

t =
puts t.username
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-04-23 08:44
(Received via mailing list)
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
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
> attr_accessor :username

Just like you used attr_reader.

Hope that helps somewhat.

This topic is locked and can not be replied to.