-
-
Save yaymukund/e5d635aaccaa5c7806c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've got some classes: | |
class User < App | |
end | |
class Team < App | |
end | |
class Pet < App | |
end | |
# Some of them have beta equivalents: | |
class Beta::User < User | |
end | |
# How can I write a class method, `to_beta`? | |
module Beta | |
def to_beta | |
# if "Beta::#{class.name}" is defined: | |
# Beta::#{class.name} | |
# else | |
# name | |
# end | |
end | |
end | |
App.send(:extend, Beta) | |
# This will let me do: | |
User.to_beta # Beta::User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment