views:

81

answers:

1

Hi,

I'm working on a ruby project using Sinatra as a framework and have a question about extending classes.

Lets say I have a User class which is extended by an Admin, does the Admin have to be defined in User.rb? I've tried putting it in Admin.rb but I get an error saying:

admin.rb:1: uninitialized constant User (NameError)

Thanks.

+2  A: 

in the Admin class, you have to require the file that contains the definition of User so that ruby knows what User is when it sees the Admin class definition.

require 'user.rb'

class Admin < User

   ...
   ...

end

stephenr
Thank you - obviously my ruby needs some serious work! :-)
Gearóid