| 1 |
###################################################################### |
| 2 |
# Core extension library |
| 3 |
# |
| 4 |
class Module |
| 5 |
# Check for an existing method in the current class before extending. IF |
| 6 |
# the method already exists, then a warning is printed and the extension is |
| 7 |
# not added. Otherwise the block is yielded and any definitions in the |
| 8 |
# block will take effect. |
| 9 |
# |
| 10 |
# Usage: |
| 11 |
# |
| 12 |
# class String |
| 13 |
# rake_extension("xyz") do |
| 14 |
# def xyz |
| 15 |
# ... |
| 16 |
# end |
| 17 |
# end |
| 18 |
# end |
| 19 |
# |
| 20 |
def rake_extension(method) |
| 21 |
if method_defined?(method) |
| 22 |
$stderr.puts "WARNING: Possible conflict with Rake extension: #{self}##{method} already exists" |
| 23 |
else |
| 24 |
yield |
| 25 |
end |
| 26 |
end |
| 27 |
end |