/tools/Ruby/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/ext/core.rb

http://github.com/agross/netopenspace · Ruby · 27 lines · 9 code · 0 blank · 18 comment · 1 complexity · 017b3a79bc7f614ae99f3e71a8d1f40a MD5 · raw file

  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