On Wednesday, June 13, 2012 10:40:08 AM UTC-4, Bartosz DziewoĆski wrote:
>
> What for? This is needlessly munging a global variable. Also, if one
> of the required scripts also happen to require something, it will
> become a relative require, too. (Unless you add some magical guard
> code for this, and then we're on a slippery slope.)
>
Ah good point. It wouldn't become relative exactly, but it could (however
unlikely) conflict name wise. However, since one is requiring relative to a
current file it is more likely that one would be aware of any such issue.
Say a local `ostruct.rb` file when one actuall wants the ruby one.
To clarify my implementation concept was something along the lines of:
def relative(&block)
dir = File.dirname(eval('__FILE__', block.binding))
$LOAD_PATH.unshift(dir)
block.call
$LOAD_PATH.delete(dir)
end
Obviously that would need to be improved upon, but that conveys the idea of
it.
Anyway, you are probably correct. It just struck me b/c a pure Ruby
implementation of #require_relative is not very robust as it has to use
`caller`, so I think its interesting that this block form never cropped up
before. If it had, I wonder if #require_relative ever would have come about
--there was such resistance to it by matz for so long.
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en