Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Apply regular expression replacements to strings while presenting the result in a “diff” like format

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 sub_diff.gemspec
README.rdoc

sub_diff -

Allows you to apply regular expression replacements to strings while presenting the result in a “diff” like format

Installation

gem install sub_diff

Usage

String#gsub_diff or String#sub_diff accept the same arguments as the standard gsub and sub methods, however the returned object is enumerable and allows you to iterate thru each replacement

replacement = 'this is a test'.gsub_diff(/(\S*is)/, 'x(\1)')

puts replacement
# => x(this) x(is) a test

replacement.each { |diff| puts [diff.changed?, diff.value_was.inspect, diff.value.inspect].join(' - ') }
# => true - "this" - "x(this)"
# => false - " " - " "
# => true - "is" - "x(is)"
# => false - " a test" - " a test"
Something went wrong with that request. Please try again.