_base.rb

Path: lib/extensions/_base.rb
Last Update: Sun Jul 18 13:32:36 CEST 2004

This file is ‘required’ by all files that implement standard class extensions as part of the "Ruby/Extensions" project.

The "Extensions" project requires 1.8.0 or greater to run, as it is too much hassle at the moment to consider supporting older versions. That may one day be implemented if demand is there. One option would be to require "shim", so that we can assume all 1.8 library methods are implemented.

This file is only of interest to developers of the package, so no detailed documentation is included here. However, by way of introduction, this is what it’s all about. Each method that is implemented as part of this package is done so through a framework implemented in this file. Take the following simple example:

  ExtensionsProject.implement(Integer, :even?, :instance) do
    class Integer
      #
      # RDoc comments.
      #
      def even?
        self % 2 == 0
      end
    end
  end

This purposes of this are as follows:

  • if the intended method (in this case IO.write) is already defined, we don’t want to overwrite it (we issue a warning and move on)
  • if the intended method is not implemented as a result of the block, we have not done as we said, and an error is raised
  • the ExtensionsProject class gathers information on which methods have been implemented, making for a very handy command-line reference (rbxtm)

The ExtensionsProject.implement method is responsible for ensuring these are so. It gives us documentation, and some assurance that the extensions are doing what we say they are doing.

[Validate]