I was watching a screencast with Jim Weirich where he started to do something like this:
class Subuser < User("Type")
end
Does Ruby let you pass arguments when defining a parent class? I can't come up with an example where that would actually work.
You can do that by declaring a method User
which takes an argument and returns a class:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With