Last active
December 17, 2015 00:29
-
-
Save christopherslee/5521813 to your computer and use it in GitHub Desktop.
Introduction to Metaprogramming: Lesson 5
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
class Customer | |
attr_reader :id, :datasource | |
def initialize(id, datasource) | |
@id = id | |
@datasource = datasource | |
end | |
def respond_to?(method) | |
datasource.respond_to?("get_#{method}_value") || super | |
end | |
def method_missing(methodname, *args) | |
super unless datasource.respond_to? "get_#{methodname}_value" | |
value = datasource.send("get_#{methodname}_value", id) | |
"#{methodname.capitalize}: #{value}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment