Created
April 27, 2009 23:19
-
-
Save anonymous/102816 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 ActsAsDuck | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def acts_as_duck(*args) | |
options = args.extract_options! | |
class_name = options[:name] || self.class.to_s + "Duck" # <-- problem here: self.class always is "Class" | |
module_eval(<<-EVAL, __FILE__, __LINE__) | |
class #{class_name} | |
def quack; puts "quack"; end | |
end | |
EVAL | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment