Guiltless monkeypatching with UUID

Suraj N. Kurapati

  1. Example in Ruby

    Feeling guilty about monkeypatching? Then free yourself from fear of name collisions and peer ridicule by naming your monkeypatched constructs with universally unique identifiers (UUIDs) and be finally at peace with your inner, monkeypatching self!

    uuidgen | sed 'y/-/_/; s/^/_/'
    

    The above command generates a UUID that conforms to /^\w+$/ and is therefore ready for use in mainstream programming languages today.

    Example in Ruby

    Although you would typically monkeypatch in Ruby like this:

    class Array
      alias __inspect__ inspect
      def inspect
        "<MonkeyPatchedArray:#{__inspect__}>"
      end
    end
    
    [1, 2, 3].inspect #=> "<MonkeyPatchedArray:[1, 2, 3]>"
    

    You can achieve the same effect, without guilt, like this:

    class Array
      alias _fba86586_e89d_4ed4_ba5c_395776a674b3 inspect
      def inspect
        "<GuiltlesslyMonkeyPatchedArray(#{
          _fba86586_e89d_4ed4_ba5c_395776a674b3
        })>"
      end
    end
    
    [1, 2, 3].inspect #=> "<GuiltlesslyMonkeyPatchedArray([1, 2, 3])>"