Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created November 15, 2010 22:10
Show Gist options
  • Select an option

  • Save nakajima/701049 to your computer and use it in GitHub Desktop.

Select an option

Save nakajima/701049 to your computer and use it in GitHub Desktop.
>> 15.minutes.class
=> Fixnum
>> Object.instance_method(:class).bind(15.minutes).call
=> ActiveSupport::Duration
@judofyr

judofyr commented Nov 15, 2010

Copy link
Copy Markdown
if defined?(BasicObject)
  bo = BasicObject
else
  bo = ActiveSupport::BasicObject
end

class Unpatcher < bo
  def initialize(obj, mod)
    @obj = obj
    @mod = mod
  end

  def method_missing(name, *args, &blk)
    begin
      meth = @mod.instance_method(name)
    rescue NoMethodError
      return @obj.send(name, *args, &blk)
    else
      return meth.bind(@obj).call(*args, &blk)
    end
  end
end

class Object
  def unpatch(mod = Object)
    Unpatcher.new(self, mod)
  end
end

15.minutes.unpatch.class # => ActiveSupport::Duration

@nakajima

Copy link
Copy Markdown
Author

Awesome.

@mtodd

mtodd commented Nov 15, 2010

Copy link
Copy Markdown

Fucking awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment