Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

ARGF#inplace_mode=

ARGF.inplace_mode = ext → ARGF

Sets the filename extension for in-place editing mode to the given String. Each file being edited has this value appended to its filename. The modified file is saved under this new name.

For example:

$ ruby argf.rb file.txt

ARGF.inplace_mode = '.bak'
ARGF.each_line do |line|
  print line.sub("foo","bar")
end

Each line of file.txt has the first occurrence of “foo” replaced with “bar”, then the new line is written out to file.txt.bak.

See also #inplace_mode #inspect #gets #internal_encoding also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0