Skip to content

Instantly share code, notes, and snippets.

@mattjmorrison
Created June 22, 2012 00:43
Show Gist options
  • Save mattjmorrison/2969549 to your computer and use it in GitHub Desktop.
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"
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