aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/object.rb
blob: 8ffe5dc90dc7f6a6dab3396f656109ffc57a1f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Object
  def instance_exec(*args, &block)
    method_name = :__temp_instance_exec_method
    singleton_class = (class << self; self; end)
    singleton_class.class_eval do
      define_method(method_name, &block)
    end

    send(method_name, *args)
  ensure
    singleton_class.class_eval do
      remove_method(method_name) if method_defined?(method_name)
    end
  end unless method_defined?(:instance_exec)
end