Skip to content

Instantly share code, notes, and snippets.

@mattjmorrison
Created June 22, 2012 01:58
Show Gist options
  • Save mattjmorrison/2969767 to your computer and use it in GitHub Desktop.
Save mattjmorrison/2969767 to your computer and use it in GitHub Desktop.
Dynamic Thor Group
source 'https://rubygems.org'
gem 'thor'
require 'thor/group'
module SampleMod
def self.included(base)
[:one, :two, :three].each do |method_name|
xvz = define_method method_name do
puts "inside #{method_name}"
end
base.send(:desc, method_name, &xvz)
end
end
end
class A < Thor::Group
include SampleMod
desc "sample"
define_method :sample do
puts "inside sample"
end
desc "sample_two"
define_method :sample_two do
puts "inside sample_two"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment