Skip to content

Instantly share code, notes, and snippets.

@yaymukund
Created October 22, 2012 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaymukund/e5d635aaccaa5c7806c2 to your computer and use it in GitHub Desktop.
Save yaymukund/e5d635aaccaa5c7806c2 to your computer and use it in GitHub Desktop.
# 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