Skip to content
Extends core File class with File.editlines to edit lines of a file in place
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
Gemfile
LICENSE.txt
README.md
Rakefile
editlines.gemspec

README.md

Editlines

Extends core File class with File.editlines to edit lines in place. File.editlines works like File.foreach except that the return value of its associated block replaces each line in place.

Installation

$ gem install editlines

Usage

Given a file such as the following one:

$ cat myfile.txt
first line
second line
third line

Running this...

require 'editlines'

File.editlines('myfile.txt') do |line|
  line.capitalize
end

will replace each line of myfile.txt in place with the return value of the associated block. In this case, we capitalized the first letter of each line.

$ cat myfile.txt
First line
Second line
Third line
You can’t perform that action at this time.