Created
March 18, 2011 13:12
-
-
Save roy/876042 to your computer and use it in GitHub Desktop.
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
module ProcessAsset | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module InstanceMethods | |
def process | |
self.send("#{asset_name}_file_name") | |
end | |
end | |
module ClassMethods | |
def process_asset(asset_name) | |
include InstanceMethods | |
define_method :asset_name do | |
"#{asset_name}" | |
end | |
end | |
end | |
end | |
class Person | |
include ProcessAsset | |
process_asset :photo | |
def photo_file_name | |
"testing.jpg" | |
end | |
end | |
p = Person.new | |
puts p.process #=> testing.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment