Skip to content

Instantly share code, notes, and snippets.

@JacobNinja
Forked from mattjmorrison/Gemfile
Created June 22, 2012 02:21
Show Gist options
  • Save JacobNinja/2969834 to your computer and use it in GitHub Desktop.
Save JacobNinja/2969834 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|
base.class_eval do
define_method method_name do
puts "inside #{method_name}"
end
desc method_name
end
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