From: Trans Date: 2006-04-26T10:14:52+09:00 Subject: Re: Rake task dependeny vs. method call Just for fun I put together this simple demonstration. # --- task.rb require 'facet/module/memoize' module Task # Store the dependencies. def task_dependencies @task_dependencies ||= {} end # Store the decriptions. def task_descriptions @task_descriptions ||= {} end # Set the description of the subsequent task. def desc( line ) @last_description = line.gsub("\n",'') end # Define a task. def task( args, &action ) if Hash === args raise ArgumentError, "#{args.size} for 1" if args.size != 1 name, deps = *(args.to_a.flatten) name = name.to_sym deps = [deps].compact.collect{ |e| e.to_sym } else name, deps = args.to_sym, [] end task_dependencies[ name ] = deps task_descriptions[ name ] = @last_description @last_description = nil (class << self; self; end).class_eval do define_method( name ) do deps.each{ |d| send(d) } action.call end memoize name end end end include Task desc "Milk the cow!" task :milk do puts "milk" end desc "Jump over the moon!" task :jump => [ :milk, :milk ] do milk; milk puts "jump" end jump puts task_descriptions[:milk] puts task_descriptions[:jump]