Skip to content
trans edited this page Aug 23, 2010 · 5 revisions

Want to see a cool trick? How about loading CORE methods automagically. It’s like Ruby’s #autoload for core extensions.

    require 'facets/opesc'

    class Object

      # This will automatically load (most) core methods
      # if they are not present when called.

      def method_missing(methodname, *a, &b)
        methodname = OpEsc.escape(methodname)
        begin
          require "facets/#{class}/#{methodname}"
          __send__(methodname, *a, &b)
        rescue LoadError
          super
        end  
      end

    end

Clone this wiki locally