Created
June 8, 2011 00:05
-
-
Save mikbe/1013510 to your computer and use it in GitHub Desktop.
Change to argf - works command line, not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kernel/loader.rb : line 279 | |
options.on "-i", "[EXT]", "Edit ARGV files in place, making backup with EXT" do |ext| | |
# in place edit mode | |
$-i = ext || true | |
end | |
kernel/common/argf.rb : line 476 | |
def advance! | |
return true unless @advance | |
unless @init | |
if ARGV.empty? | |
@advance = false | |
@stream = STDIN | |
if $-i | |
$stdout.close | |
$stdout = @original_stdout | |
File.delete(@original_file) if @original_file | |
end | |
@filename = "-" | |
@use_stdin_only = true | |
return true | |
end | |
@init = true | |
end | |
return false if @use_stdin_only || ARGV.empty? | |
@advance = false | |
file = ARGV.shift | |
if $-i | |
if $-i == true # yes, I mean specifically true | |
require 'tempfile' | |
new_file_name = Tempfile.new(file).path | |
@original_file = new_file_name | |
else | |
new_file_name = file + $-i | |
end | |
File.rename file, new_file_name | |
$stdout, @original_stdout = File.open(file, "w"), $stdout | |
file = new_file_name | |
end | |
@stream = (file == "-" ? STDIN : File.open(file, "r")) | |
@filename = file | |
return true | |
end | |
private :advance! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment