Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Monkey patch objects using Ruby 2.0 refinements, if available.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Use duck typing instead of RUBY_VERSION.
spec Use duck typing instead of RUBY_VERSION.
.gitignore Now you're monkey patching with gas.
.travis.yml Don't email me, bro. [ci skip]
Gemfile Now you're monkey patching with gas.
LICENSE.txt Now you're monkey patching with gas.
Rakefile Now you're monkey patching with gas.
guerilla_patch.gemspec Actually, it just needs to be told what test command to use.

Build Status


GuerillaPatch is a Ruby gem to ease the transition to Ruby 2.0 when redefining behavior in existing objects (monkey patching). Ruby 2.0 introduces a new feature called refinements which allows you to create monkey patches that only exist in a scope where the refinement is explicitly included, preventing your changes from affected code that has not opted in.

Using GuerillaPatch, you can use a common interface for writing a monkey patch that will use refinements if available, working seemlessly for both Ruby 1.9 and Ruby 2.0.


Add this line to your application's Gemfile:

gem 'guerilla_patch'

And then execute:

$ bundle

Or install it yourself with:

$ gem install guerilla_patch


To create a new monkey patch, use GuerillaPatch.patch. The first argument is the object you are patching, and the second argument is the name to use for the refinement if run under Ruby 2.0. Pass a block with the methods you want to add to the object, or any other modifications you want to make.

GuerillaPatch.patch(Fixnum, "TimeExtensions") do
  def minutes
    self * 60

Then, in Ruby 1.9:

2.minutes # => 120

And in Ruby 2.0:

class MyApp
  using TimeExtensions

  def minutes_to_seconds(m)
end # => 120
Something went wrong with that request. Please try again.