Module Weave
In: weave.rb

The module `Weave` contains the classes and methods to perform live native monkey patching.

Methods

Classes and Modules

Class Weave::Library
Class Weave::Symbol

Public Class methods

This is the actual core of weave. It‘s just a thin wrapper of MRI‘s native `rb_define_method` C-function.

Parameters:

  • klass : the class to add a method to
  • name : the name of the method to add
  • sym : the Weave::Symbol that addresses the native implementation
  • arity : the number of args this function takes (Note 1)

returns a reference to the previous definition of the method or nil if there isn‘t one. In consequence `sym` doesn‘t strictly need to be a Weave::Symbol, it may also be whatever the last call to `rb_define_method` returned, in case you‘d like to restore default behaviour.

(Note 1: from README.EXT in the ruby dist)

    The `argc' represents the number of the arguments to the C function,
    which must be less than 17.  But I doubt you'll need that many.

    If `argc' is negative, it specifies the calling sequence, not number of
    the arguments.

    If argc is -1, the function will be called as:

      VALUE func(int argc, VALUE *argv, VALUE obj)

    where argc is the actual number of arguments, argv is the C array of
    the arguments, and obj is the receiver.

    If argc is -2, the arguments are passed in a Ruby array. The function
    will be called like:

      VALUE func(VALUE obj, VALUE args)

    where obj is the receiver, and args is the Ruby array containing
    actual arguments.

This is the other core of weave. It‘s just a thin wrapper of MRI‘s native `rb_define_singleton_method` C-function.

It‘s very similar to `rb_define_method`, so check that methods documentation as well, please.

Parameters:

  * object: the object to add a method to
  * name  : the name of the method to add
  * sym   : the Weave::Symbol that addresses the native implementation
  * arity : the number of args this function takes

[Validate]