[Rake-devel] Environment changes in the beta

James M. Lawrence quixoticsycophant at gmail.com
Thu Mar 3 16:29:50 EST 2011


Currently rake/dsl.rb says

  include Rake::DSL

Of course the top-level include method is special (and probably
misnamed), having the effect of

  class Object
    include Rake::DSL
  end

If the top-level object were extended instead, then the DSL would be
available at the global scope while not interfering with other classes
and modules. Running this with ruby alone (not through rake),

  require 'rake'

  extend Rake::DSL

  task :default do  # OK
    # ...
  end

  module MyStuff
    task :foo do  # => NoMethodError for `task'
      # ...
    end
  end

Users decide whether to have DSL in their classes/modules, and whether
at the singleton or instance level. That is,

  module MyStuff
    extend Rake::DSL

    task :foo do
      # ...
    end
  end

or

  class MyStuff
    include Rake::DSL

    def initialize
      task :foo do
        # ...
      end
    end
  end

Thus my proposal is that bin/rake simply extend Rake::DSL at the top
level rather than include it. The readme would cover how to use the
DSL in one's own classes with examples like the above.

I'm guessing that environment.rb was a noble effort to keep 'import'
alive, resolving the jruby conflict while maintaining backward
compatibility. Perhaps 'import' can be left out of Rake::DSL when
RUBY_ENGINE == "jruby", and/or deprecate import in favor of
Rake.import. Such a conflict may have no good solution. (Even though
it's not fair because you had it first :)


More information about the Rake-devel mailing list