开发者

Inheritance in Ruby / Sinatra

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜