Skip to content

Instantly share code, notes, and snippets.

Created April 27, 2009 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/102816 to your computer and use it in GitHub Desktop.
Save anonymous/102816 to your computer and use it in GitHub Desktop.
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