Module: Kernel

Defined in:
lib/library/autoload.rb,
lib/library.rb,
lib/library/kernel.rb

Overview

Ruby’s autoload method does not use the normal require mechanisms, therefore if we wish to support it we will have to override and create our own system. OTOH Matz has said autoload will go away in Ruby 2.0, so maybe we can just let this go and not worry about it.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__load__Object



10
# File 'lib/library/kernel.rb', line 10

alias __load__    load

.__require__Object



9
# File 'lib/library/kernel.rb', line 9

alias __require__ require

.acquire(pathname, options = {}) ⇒ true, false

Acquire feature - This is Roll’s modern require/load method. It differs from the usual ‘#require` or `#load` primarily by the fact that it will search the current loading library, i.e. the one belonging to the feature on the top of the #LOAD_STACK, before looking elsewhere. The reason we can’t adjust ‘#require` to do this is becuase it could load a local feature when a non-local feature was intended. For example, if a library contained ’fileutils.rb’ then this would be loaded rather the Ruby’s standard library. When using ‘#acquire`, one would have to use the `ruby/` prefix to ensure the Ruby library gets loaded.

Parameters:

  • pathname (String)

    The pathname of the feature to acquire.

  • options (Hash) (defaults to: {})

    Load options are ‘:wrap`, `:load`, `:legacy` and `:search`.

Returns:

  • (true, false)

    Was the feature newly required or successfully loaded, depending on the ‘:load` option settings.



39
40
41
# File 'lib/library/kernel.rb', line 39

def acquire(pathname, options={}) #, &block)
  Library.acquire(pathname, options) #, &block)
end

.library(name, constraint = nil, &block) ⇒ Library

Activate a library, same as ‘Library.instance` but will raise and error if the library is not found. This can also take a block to yield on the library.

Parameters:

  • name (String)

    The library’s name.

  • constraint (String) (defaults to: nil)

    A valid version constraint.

Returns:

  • (Library)

    The Library instance.



525
526
527
# File 'lib/library.rb', line 525

def library(name, constraint=nil, &block) #:yield:
  Library.activate(name, constraint, &block)
end

.load(pathname, options = {}) ⇒ true, false

Load feature - This is the same as acquire except that the ‘:legacy` and `:load` options are fixed as `true`.

Parameters:

  • pathname (String)

    The pathname of the feature to load.

  • options (Hash) (defaults to: {})

    Load options can be :wrap and :search.

Returns:

  • (true, false)

    if feature was successfully loaded



75
76
77
# File 'lib/library/kernel.rb', line 75

def load(pathname, options={}) #, &block)
  Library.load(pathname, options) #, &block)
end

.require(pathname, options = {}) ⇒ true, false

Require feature - This is the same as acquire except that the ‘:legacy` option is fixed as `true`.

Parameters:

  • pathname (String)

    The pathname of the feature to require.

  • options (Hash) (defaults to: {})

    Load options can be ‘:wrap`, `:load` and `:search`.

Returns:

  • (true, false)

    if feature was newly required



57
58
59
# File 'lib/library/kernel.rb', line 57

def require(pathname, options={}) #, &block)
  Library.require(pathname, options) #, &block)
end

Instance Method Details

#__LIBRARY__Library

In which library is the current file participating?

Returns:

  • (Library)

    The library currently loading features.



508
509
510
# File 'lib/library.rb', line 508

def __LIBRARY__
  $LOAD_STACK.last.library
end

#__load__Object



14
# File 'lib/library/kernel.rb', line 14

alias __load__    load

#__require__Object



13
# File 'lib/library/kernel.rb', line 13

alias __require__ require

#acquire(pathname, options = {}) ⇒ true, false (private)

Acquire feature - This is Roll’s modern require/load method. It differs from the usual ‘#require` or `#load` primarily by the fact that it will search the current loading library, i.e. the one belonging to the feature on the top of the #LOAD_STACK, before looking elsewhere. The reason we can’t adjust ‘#require` to do this is becuase it could load a local feature when a non-local feature was intended. For example, if a library contained ’fileutils.rb’ then this would be loaded rather the Ruby’s standard library. When using ‘#acquire`, one would have to use the `ruby/` prefix to ensure the Ruby library gets loaded.

Parameters:

  • pathname (String)

    The pathname of the feature to acquire.

  • options (Hash) (defaults to: {})

    Load options are ‘:wrap`, `:load`, `:legacy` and `:search`.

Returns:

  • (true, false)

    Was the feature newly required or successfully loaded, depending on the ‘:load` option settings.



39
40
41
# File 'lib/library/kernel.rb', line 39

def acquire(pathname, options={}) #, &block)
  Library.acquire(pathname, options) #, &block)
end

#library(name, constraint = nil, &block) ⇒ Library (private)

Activate a library, same as ‘Library.instance` but will raise and error if the library is not found. This can also take a block to yield on the library.

Parameters:

  • name (String)

    The library’s name.

  • constraint (String) (defaults to: nil)

    A valid version constraint.

Returns:

  • (Library)

    The Library instance.



525
526
527
# File 'lib/library.rb', line 525

def library(name, constraint=nil, &block) #:yield:
  Library.activate(name, constraint, &block)
end

#load(pathname, options = {}) ⇒ true, false (private)

Load feature - This is the same as acquire except that the ‘:legacy` and `:load` options are fixed as `true`.

Parameters:

  • pathname (String)

    The pathname of the feature to load.

  • options (Hash) (defaults to: {})

    Load options can be :wrap and :search.

Returns:

  • (true, false)

    if feature was successfully loaded



75
76
77
# File 'lib/library/kernel.rb', line 75

def load(pathname, options={}) #, &block)
  Library.load(pathname, options) #, &block)
end

#require(pathname, options = {}) ⇒ true, false (private)

Require feature - This is the same as acquire except that the ‘:legacy` option is fixed as `true`.

Parameters:

  • pathname (String)

    The pathname of the feature to require.

  • options (Hash) (defaults to: {})

    Load options can be ‘:wrap`, `:load` and `:search`.

Returns:

  • (true, false)

    if feature was newly required



57
58
59
# File 'lib/library/kernel.rb', line 57

def require(pathname, options={}) #, &block)
  Library.require(pathname, options) #, &block)
end