Forum: Ruby-core [ruby-trunk - Feature #7611][Open] Focal method for all loads/requires

Posted by Thomas Sawyer (7rans)
on 2012-12-23 15:51
(Received via mailing list)
Issue #7611 has been reported by trans (Thomas Sawyer).

----------------------------------------
Feature #7611: Focal method for all loads/requires
https://bugs.ruby-lang.org/issues/7611

Author: trans (Thomas Sawyer)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor


=begin
Presently Ruby has seven methods for importing code. These are:

* (({Kernel#load}))
* (({Kernel#require}))
* (({Kernel#relative_require}))
* (({Kernel.load}))
* (({Kernel.require}))
* (({Kernel.relative_require}))
* (({Kernel#autoload}))

Even though the Kernel module methods do the same thing as the instance 
methods, all of these act independently. If you need to tap into or 
override code loading in general it means doing so for each and every 
one.

Would it not be much more elegant if they all called upon one focal 
method? Lacking another name for this example, lets call it 
(({#open_eval()})). The method would take a path argument and options 
for (({feature})), (({relative})) and (({wrap})), where if (({feature})) 
is true then it is a "require", otherwise it is a "load".

  def open_eval(path, feature: false, relative: false, wrap: nil)
    ...
  end

All the other seven methods listed above would route to this one method. 
So it would then be possible to monitor or override this behavior, e.g. 
like RubyGems does, via a single interface.

Note, even if this feature request is not accepted, I would like to get 
some opinion on it, b/c I am currently working on a project where I have 
to do this (specifically I am in need of require/load callbacks). For 
the purpose I have created another reusable gem for it and I want to get 
an idea of what would be considered appropriate API for it.
=end
Posted by zzak (Zachary Scott) (Guest)
on 2012-12-23 18:48
(Received via mailing list)
Issue #7611 has been updated by zzak (Zachary Scott).


IRB adds even more requires, but I digress.
----------------------------------------
Feature #7611: Focal method for all loads/requires
https://bugs.ruby-lang.org/issues/7611#change-35032

Author: trans (Thomas Sawyer)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor


=begin
Presently Ruby has seven methods for importing code. These are:

* (({Kernel#load}))
* (({Kernel#require}))
* (({Kernel#relative_require}))
* (({Kernel.load}))
* (({Kernel.require}))
* (({Kernel.relative_require}))
* (({Kernel#autoload}))

Even though the Kernel module methods do the same thing as the instance 
methods, all of these act independently. If you need to tap into or 
override code loading in general it means doing so for each and every 
one.

Would it not be much more elegant if they all called upon one focal 
method? Lacking another name for this example, lets call it 
(({#open_eval()})). The method would take a path argument and options 
for (({feature})), (({relative})) and (({wrap})), where if (({feature})) 
is true then it is a "require", otherwise it is a "load".

  def open_eval(path, feature: false, relative: false, wrap: nil)
    ...
  end

All the other seven methods listed above would route to this one method. 
So it would then be possible to monitor or override this behavior, e.g. 
like RubyGems does, via a single interface.

Note, even if this feature request is not accepted, I would like to get 
some opinion on it, b/c I am currently working on a project where I have 
to do this (specifically I am in need of require/load callbacks). For 
the purpose I have created another reusable gem for it and I want to get 
an idea of what would be considered appropriate API for it.
=end
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-02-22 01:28
(Received via mailing list)
Issue #7611 has been updated by ko1 (Koichi Sasada).

Assignee set to matz (Yukihiro Matsumoto)


----------------------------------------
Feature #7611: Focal method for all loads/requires
https://bugs.ruby-lang.org/issues/7611#change-36752

Author: trans (Thomas Sawyer)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
Presently Ruby has seven methods for importing code. These are:

* (({Kernel#load}))
* (({Kernel#require}))
* (({Kernel#relative_require}))
* (({Kernel.load}))
* (({Kernel.require}))
* (({Kernel.relative_require}))
* (({Kernel#autoload}))

Even though the Kernel module methods do the same thing as the instance 
methods, all of these act independently. If you need to tap into or 
override code loading in general it means doing so for each and every 
one.

Would it not be much more elegant if they all called upon one focal 
method? Lacking another name for this example, lets call it 
(({#open_eval()})). The method would take a path argument and options 
for (({feature})), (({relative})) and (({wrap})), where if (({feature})) 
is true then it is a "require", otherwise it is a "load".

  def open_eval(path, feature: false, relative: false, wrap: nil)
    ...
  end

All the other seven methods listed above would route to this one method. 
So it would then be possible to monitor or override this behavior, e.g. 
like RubyGems does, via a single interface.

Note, even if this feature request is not accepted, I would like to get 
some opinion on it, b/c I am currently working on a project where I have 
to do this (specifically I am in need of require/load callbacks). For 
the purpose I have created another reusable gem for it and I want to get 
an idea of what would be considered appropriate API for it.
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.