How can you track the complete sequence and order of a request in a Ruby application like a tree?

How can you display the "require" hierarchy that runs in a Ruby application?

Some files require files that require additional files.

However, by launching the application in debug mode, you call only a subset of the necessary files - only those that are used by any subset of the functionality used by your application at any given time.

How can you display an exhaustive hierarchy of all requirements in an application in the form of a tree?

+5
source share
1 answer

, load, require, . . , . , ActiveSupport const_missing (ConstantName.to_s.underscore require 'constant_name'). , , "require".

, ( active_support)

  $require_level = []
  alias :orig_require :require
  def require(file)
    puts "#{$require_level.join}#{file}"
    $require_level << "-"
    r = orig_require(file)
    $require_level.pop
    r
  end

  require 'foo'
  require 'baz'


 ben@legba-2:~ $ ruby check_requires.rb 
 foo
 -bar
 baz

.

EDIT:

, . . . . , , , 1 , "- # {file}" . , , , . , , , . .

const_missing method_missing. , , AnObject.some_unknown_method ruby ​​ AnObject.method_missing(:some_unknown_method) , NoMethodError, SomeUnknownConstant a const_missing(:SomeUnknownConstant) , NameError. Rails const_missing , , . , , . SomeUnknownConstant some_unknown_constant.rb

.

+9

All Articles