Ruby 1.8.5: cannot use rdoc/usage from a gem executable

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

In Ruby 1.8.5, RDoc::usage_no_exit parses usage information from the
earliest file in the Kernel#caller list. This works well if you directly
invoke the file containing the usage information.

However, when a Ruby program (containing usage information in the same
file) is shipped as part of the Gem::Specification#executables array,
RubyGems creates a proxy for that program in the system bin/ directory.
Because of the proxy, the Ruby program is not invoked directly, and
therefore RDoc::usage_no_exit is parsing the usage information of the
proxy!

The way I’ve solved it, for now, is to define a RDoc::usage_from_file
method that parses usage information from a given file, as follows.

$ diff -bc lib/rdoc/usage.rb{.orig,}
*** lib/rdoc/usage.rb.orig 2006-08-28 23:39:39.000000000 -0700

  • — lib/rdoc/usage.rb 2006-08-28 23:41:41.000000000 -0700

*** 97,103 ****
# Display usage
def RDoc.usage_no_exit(*args)
main_program_file = caller[-1].sub(/:\d+$/, ‘’)
! comment = File.open(main_program_file) do |file|
find_comment(file)
end

  • — 97,108 ----

    Display usage

    def RDoc.usage_no_exit(*args)
    main_program_file = caller[-1].sub(/:\d+$/, ‘’)
    ! usage_from_file(main_program_file)
    ! end
    !
    ! # Display usage from the given file
    ! def RDoc.usage_from_file(input_file, *args)
    ! comment = File.open(input_file) do |file|
    find_comment(file)
    end

Does anyone have other ideas or solutions? Is it too brash to suggest
that
such functionality be added to RDoc?

Thanks for your consideration.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFE8+T5mV9O7RYnKMcRAmzFAJsGZ0RRKII/BqmRh5TBUejmOtrAfACdG7Kz
o2kBe93ypOFMlSPmGaarGN4=
=Aycb
-----END PGP SIGNATURE-----