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
- .__load__ ⇒ Object
- .__require__ ⇒ Object
-
.acquire(pathname, options = {}) ⇒ true, false
Acquire feature - This is Roll’s modern require/load method.
-
.library(name, constraint = nil, &block) ⇒ Library
Activate a library, same as ‘Library.instance` but will raise and error if the library is not found.
-
.load(pathname, options = {}) ⇒ true, false
Load feature - This is the same as acquire except that the ‘:legacy` and `:load` options are fixed as `true`.
-
.require(pathname, options = {}) ⇒ true, false
Require feature - This is the same as acquire except that the ‘:legacy` option is fixed as `true`.
Instance Method Summary collapse
-
#__LIBRARY__ ⇒ Library
In which library is the current file participating?.
- #__load__ ⇒ Object
- #__require__ ⇒ Object
-
#acquire(pathname, options = {}) ⇒ true, false
private
Acquire feature - This is Roll’s modern require/load method.
-
#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.
-
#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`.
-
#require(pathname, options = {}) ⇒ true, false
private
Require feature - This is the same as acquire except that the ‘:legacy` option is fixed as `true`.
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.
39 40 41 |
# File 'lib/library/kernel.rb', line 39 def acquire(pathname, ={}) #, &block) Library.acquire(pathname, ) #, &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.
525 526 527 |
# File 'lib/library.rb', line 525 def library(name, constraint=nil, &block) #:yield: Library.activate(name, constraint, &block) end |
Instance Method Details
#__LIBRARY__ ⇒ Library
In which library is the current file participating?
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.
39 40 41 |
# File 'lib/library/kernel.rb', line 39 def acquire(pathname, ={}) #, &block) Library.acquire(pathname, ) #, &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.
525 526 527 |
# File 'lib/library.rb', line 525 def library(name, constraint=nil, &block) #:yield: Library.activate(name, constraint, &block) end |