Module: Rbyte::RequirePatch
- Defined in:
- lib/rbyte.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#require_with_rbyte(name) ⇒ Object
Searches load path for rbc files.
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rbyte.rb', line 5 def self.included(base) base.class_eval do alias :require_without_rbyte :require alias :require :require_with_rbyte end end |
Instance Method Details
#require_with_rbyte(name) ⇒ Object
Searches load path for rbc files. If a normal Ruby file exists with with a more recent mtime, then that will be loaded instead. Delegates to Ruby’s normal require if a file can’t be found.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rbyte.rb', line 17 def require_with_rbyte(name) path = Rbyte.search_for_rbc_file(name) unless path return require_without_rbyte(name) end # File already loaded? return false if $".include?(path) # File is plain ruby if path =~ /\.rb\Z/ return require_without_rbyte(path) end # Find out if rbc file is out of date rb_path = path.gsub(/\.rbc\Z/, ".rb") if File.file?(rb_path) && mtime = File.mtime(rb_path) if File.mtime(path) < mtime return require_without_rbyte(rb_path) end end # Evaluate rbc file Rbyte.decompile_file(path) # Add to loaded files $" << File.(path) true end |