Created
June 22, 2012 01:58
-
-
Save mattjmorrison/2969767 to your computer and use it in GitHub Desktop.
Dynamic Thor Group
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
source 'https://rubygems.org' | |
gem 'thor' |
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
thor a |
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
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