Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
class User
def initiaize(profile)
@profile = profile
%w(doctor patient).each do |profile_type|
self.send(:define_method, "#{profile_type}?".to_sym) do
return @profile == profile_type
# Some of the benefits of using this approach to meta-programming are:
# * get respond_to?(:doctor?) works as expected
# * speed improvements as the methods are defined at compile time rather than the check logic run every time method_missing is run
# * In my opinion, cleaner code.
# Some other ideas that I agree with when it comes to meta-prgramming:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment