From: Trans Date: 2005-08-06T04:51:06+09:00 Subject: Re: How safe: overridding require Hello-- nobuyoshi nakada wrote: > What do you mean by "safe"? Safe in that it won't cause problems w/ other's work --with Gems, for instance. > > require 'uri' > > > > module Kernel > > > > alias_method :require_prefacets, :require > > def require( *args ) > > require_esc( *args ) > > end > > > > def require_esc( fpath ) > > require_prefacets( File.join( File.dirname( fpath ), URI.escape( File.basename( fpath ), /\W/ ) ) ) > > end > > > > end > > $ irb -ruri > irb(main):001:0> fpath = "foo.rb" > => "foo.rb" > irb(main):002:0> File.join(File.dirname(fpath), URI.escape(File.basename(fpath), /\W/)) > => "./foo%2Erb" > > "foo.rb" and "./foo.rb" are diffrenet for `require', and it > doesn't load files have not suffix. Thanks. Yes, I discovered soon after posting. Here's my current verson: require 'uri' module Kernel alias_method :require_prefacets, :require def require( *args ) require_esc( *args ) end def require_esc( fpath ) fs = fpath.split('/') fn = fs.pop dn = fs.join('/') dn += '/' unless dn.empty? en = URI.escape( File.basename( fn ), /[^.-_\w]/ ) require_prefacets( "#{dn}#{en}" ) end alias_method :require_facet, :require_esc end Works much better. Should there be any error caching on this sort of thing? T.