Created
June 22, 2012 00:43
-
-
Save mattjmorrison/2969549 to your computer and use it in GitHub Desktop.
How the crap do I use define_method in a module? -- needs "self.included"
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 SampleMod | |
def self.included(base) | |
[:one, :two, :three].each do |method_name| | |
define_method method_name do | |
puts "inside #{method_name}" | |
end | |
end | |
end | |
end | |
class A | |
include SampleMod | |
define_method :sample do | |
puts "inside sample" | |
end | |
end | |
A.new.send(:sample) | |
begin | |
A.new.send(:one) | |
rescue | |
puts "Crap it didn't work" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment