noreply / rubyforge.org wrote:
> Bugs item #3344, was opened at 2006-01-27 14:26
> You can respond by visiting: 
> http://rubyforge.org/tracker/?func=detail&atid=1698&aid=3344&group_id=426
> 
> Category: Standard Library
> Group: None
> Status: Open
> Resolution: None
> Priority: 3
> Submitted By: Brent Northam (bnortham)
> Assigned to: Nobody (None)
> Summary: RDoc.usage doesn't parse caller correctly on windows
> 
> Initial Comment:
> In using rdoc/usage to output usage information for a commandline utility on Windows I came across this.
> 
> In RDoc.usage_no_exit, this code intends to parse out the filename of the calling script with:
> 
> main_program_file, = caller[-1].split(/:/,2)
> comment = File.open(main_program_file) do |file|
>      find_comment(file)
> end
> 
> The output for main_program_file on Windows is always simply the drive letter, since 2 colons are present in caller[-1].  My hack workaround, which is I'm sure 100% inapropriate as a real fix since I'm new to ruby was:
> 
> drive,main_program_file, = caller[-1].split(/:/,2)
>     comment = File.open(drive + ":" + main_program_file) do |file|
>       find_comment(file)
>     end
> 
> How are platform-specific issues like this handled?

A better solution is this: main_program_file = caller.last.split(":")[-2]

You'll always want the second to last argument.  Works on all platforms, and 
even works with Windows' UNC paths (which don't have a leading drive letter).

Regards,

Dan