Module: Polyglot

### Home Classes Methods

### In Files

- lib/polyglot.rb
- lib/polyglot/version.rb

### Namespace

- CLASS Polyglot::NestedLoadError
- CLASS Polyglot::PolyglotLoadError

### Methods

- ::find
- ::load
- ::register

### Files

- README.txt

### Class/Module Index

Quicksearch

- Polyglot
- Polyglot::NestedLoadError
- Polyglot::PolyglotLoadError
- Kernel

No matching classes.

# Polyglot

### Public Class Methods

find(file, *options, &block) click to toggle source

    # File lib/polyglot.rb, line 25
    def self.find(file, *options, &block)
      is_absolute = Pathname.new(file).absolute?
      (is_absolute ? [""] : $:).each{|lib|
        base = is_absolute ? "" : lib+File::SEPARATOR
        # In Windows, repeated SEPARATOR chars have a special meaning, avoid adding them
        matches = Dir["#{base}#{file}{,.#{@registrations.keys*',.'}}"]
        # Revisit: Should we do more do if more than one candidate found?
        $stderr.puts "Polyglot: found more than one candidate for #{file}: #{matches*", "}" if matches.size > 1
        if path = matches[0]
          return [ path, @registrations[path.gsub(/.*\./,'')]]
        end
      }
      return nil
    end

load(*a, &b) click to toggle source

    # File lib/polyglot.rb, line 40
    def self.load(*a, &b)
      file = a[0].to_str
      return if @loaded[file] # Check for $: changes or file time changes and reload?
      begin
        source_file, loader = Polyglot.find(file, *a[1..-1], &b)
        if (loader)
          begin
            loader.load(source_file)
            @loaded[file] = true
          rescue LoadError => e
            raise Polyglot::NestedLoadError.new(e)
          end
        else
          raise PolyglotLoadError.new("Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}")
        end
      end
    end

register(extension, klass) click to toggle source

    # File lib/polyglot.rb, line 18
    def self.register(extension, klass)
      extension = [extension] unless Array === extension
      extension.each{|e|
        @registrations[e] = klass
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.