Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在观看 Jim Weirich 的截屏视频,他开始做这样的事情:
class Subuser < User("Type") end
Ruby 是否允许您在定义父类时传递参数?我想不出一个实际可行的例子。
你可以通过声明一个User接受一个参数并返回一个类的方法来做到这一点:
User
class Admin end class Client end def User(arg) case arg when :admin Admin when :client Client end end class Subuser < User(:admin) end Subuser.superclass # => Admin