Skip to content

Loading debug gem breaks blankslate gem #757

@jvilk-stripe

Description

@jvilk-stripe

Your environment

  • ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
  • rdbg -v: rdbg 1.6.2

Describe the bug

The debug gem undefines and redefines singleton_method_added.

The blankslate gem provides a "abstract base class with no predefined methods" except for some core Ruby builtins. "BlankSlate is useful as a base class when writing classes that depend upon method_missing (e.g. dynamic proxies)", so it only works if singleton_method_added is available. However, it hides singleton_method_added because it's redefined by the debug gem.

This problem does not occur when the debug gem is not required.

To Reproduce

require 'debug'
require 'blankslate'

BlankSlate.new.singleton_method_added

Buggy output -- the method isn't defined:

Traceback (most recent call last):
repro.rb:4:in `<main>': undefined method `singleton_method_added' for #<BlankSlate:0x000055a654b12fb0> (NoMethodError)

Expected behavior

The method is defined, but private:

Traceback (most recent call last):
repro.rb:3:in `<main>': private method `singleton_method_added' called for #<BlankSlate:0x000055d758dcd540> (NoMethodError)

Workaround

We can work around the bug by explicilty unhiding this method, or by requiring blankslate before debug:

BlankSlate.reveal(:singleton_method_added)

Additional context

The problem is caused by this code in the debug gem:

debug/lib/debug/session.rb

Lines 1686 to 1689 in 19b4dde

class ::BasicObject
undef singleton_method_added
def singleton_method_added mid; end
end

Why does the debug gem redefine this method?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions