Skip to content

Instantly share code, notes, and snippets.

@christopherslee
Last active December 17, 2015 00:29
Show Gist options
  • Save christopherslee/5521697 to your computer and use it in GitHub Desktop.
Save christopherslee/5521697 to your computer and use it in GitHub Desktop.
Introduction to Metaprogramming: Lesson 3
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
end
def self.has_field(fieldname)
define_method fieldname do
value = datasource.send("get_#{fieldname}_value", id)
"#{fieldname.capitalize}: #{value}"
end
end
has_field :first
has_field :last
has_field :email
has_field :age
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment