Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Monkeypatch without aliasing methods. Ever.

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 CHANGELOG
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 benchmark.rb
Octocat-spinner-32 freedom_patch.gemspec
README.markdown

Freedom Patch

Monkeypatch without aliasing methods. Ever.

Wait, what?

Suppose you have some 3rd party code:

class VendorLib
  def foo
    10
  end
end

And you want to add 1 to what foo returns.

It'd be great if you could just "super and add 1":

module Hack
  def foo
    super + 1
  end
end
VendorLib.include(Hack)

But this won't work, because VendorLib#foo shadows Hack#foo.

Well, now you can.

require 'freedom_patch'

module Hack
  def foo
    super + 1
  end
end

VendorLib.freedom_patch(Hack)

FREEDOM!

Install

gem install freedom_patch

My Namespace!

Don't want to pollute Module with the freedom_patch?

Do require 'freedom_patch/clean' instead of require 'freedom_patch', and patch your way to independence thusly:

FreedomPatch.apply(Hack, VendorLib)

Performance

It's shit.

$ ruby benchmark.rb
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
                     user     system      total        real
with freedom_patch   2.720000   0.020000   2.740000 (  2.741546)
aliasing             1.010000   0.030000   1.040000 (  1.043165)

But hey, it was fun. :)

Note on Patches/Pull Requests

Copyright

Copyright (c) George Ogata. See LICENSE for details.

Something went wrong with that request. Please try again.