Class
Module
In: lib/rake/ext/module.rb
Parent: Object

Rake extensions to Module.

Methods

const_missing, rake_extension,
Public Instance methods
const_missing(const_name)

Check for deprecated uses of top level (i.e. in Object) uses of Rake class names. If someone tries to reference the constant name, display a warning and return the proper object. Using the —classic-namespace command line option will define these constants in Object and avoid this handler.

    # File lib/rake/ext/module.rb, line 42
42:   def const_missing(const_name)
43:     case const_name
44:     when :Task
45:       Rake.application.const_warning(const_name)
46:       Rake::Task
47:     when :FileTask
48:       Rake.application.const_warning(const_name)
49:       Rake::FileTask
50:     when :FileCreationTask
51:       Rake.application.const_warning(const_name)
52:       Rake::FileCreationTask
53:     when :RakeApp
54:       Rake.application.const_warning(const_name)
55:       Rake::Application
56:     else
57:       rake_original_const_missing(const_name)
58:     end
59:   end
rake_extension(method) {|| ...}

Check for an existing method in the current class before extending. IF the method already exists, then a warning is printed and the extension is not added. Otherwise the block is yielded and any definitions in the block will take effect.

Usage:

  class String
    rake_extension("xyz") do
      def xyz
        ...
      end
    end
  end
    # File lib/rake/ext/module.rb, line 26
26:   def rake_extension(method)
27:     if method_defined?(method)
28:       $stderr.puts "WARNING: Possible conflict with Rake extension: #{self}##{method} already exists"
29:     else
30:       yield
31:     end
32:   end