Sha256: 15030db5c895ebbf933e045cab8c1517175292d372d6f6d0cf32e7fdaa145ad6

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

module VCR
  # taken directly from backports:
  # https://github.com/marcandre/backports/blob/v1.18.2/lib/backports/basic_object.rb
  class BasicObject
    KEEP = [:instance_eval, :instance_exec, :__send__,
            "instance_eval", "instance_exec", "__send__"]
    # undefine almost all instance methods
    begin
      old_verbose, $VERBOSE = $VERBOSE, nil # silence the warning for undefining __id__
      (instance_methods - KEEP).each do |method|
        undef_method method
      end
    ensure
      $VERBOSE = old_verbose
    end

    class << self
      def === (cmp)
        true
      end

      # Let's try to keep things clean, in case methods have been added to Object
      # either directly or through an included module.
      # We'll do this whenever a class is derived from BasicObject
      # Ideally, we'd do this by trapping Object.method_added
      # and M.method_added for any module M included in Object or a submodule
      # Seems really though to get right, but pull requests welcome ;-)
      def inherited(sub)
        BasicObject.class_eval do
          (instance_methods - KEEP).each do |method|
            if Object.method_defined?(method) && instance_method(method).owner == Object.instance_method(method).owner
              undef_method method
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vcr-1.6.0 lib/vcr/util/basic_object.rb
vcr-1.5.1 lib/vcr/util/basic_object.rb
vcr-1.5.0 lib/vcr/util/basic_object.rb
vcr-1.4.0 lib/vcr/basic_object.rb
vcr-1.3.3 lib/vcr/basic_object.rb
vcr-1.3.2 lib/vcr/basic_object.rb
vcr-1.3.1 lib/vcr/basic_object.rb
vcr-1.3.0 lib/vcr/basic_object.rb