Module: Mechanize::Prependable

Defined in:
lib/mechanize/prependable.rb

Overview

Fake implementation of prepend(), which does not support overriding inherited methods nor methods that are formerly overridden by another invocation of prepend().

Here's what .prepend() does:

  • Create an anonymous stub module (hereinafter ) and define # that calls #_without_ for each instance method of .

  • Rename # to #_without_ for each instance method of .

  • Include and into in that order.

This way, a call of # is dispatched to , which may call super which is dispatched to #, which finally calls #_without_ which is used to be called #.

Usage:

class Mechanize
  # module with methods that overrides those of X
  module Y
  end

  unless X.respond_to?(:prepend, true)
    require 'mechanize/prependable'
    X.extend(Prependable)
  end

  class X
    prepend Y
  end
end