开发者

Inheritance in Ruby / Sinatra

开发者 https://www.devze.com 2023-01-02 12:35 出处:网络
I\'m working on a ruby project using Sinatra as a framework and have a question about extending classes.

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,开发者_JS百科 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消