Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class User
def initiaize(profile)
@profile = profile
end
%w(doctor patient).each do |profile_type|
self.send(:define_method, "#{profile_type}?".to_sym) do
return @profile == profile_type
end
end
end
# 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: http://patshaughnessy.net/2011/12/20/learning-from-the-masters-part-2-three-metaprogramming-best-practices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.