【发布时间】:2019-08-17 21:53:32
【问题描述】:
我目前正在逐步检查gitlab_development_kit gem 的代码以了解它是如何工作的。
我目前在this line of code,我在该行的上方和下方放置了一个调试器点。
3: require 'byebug'
4: byebug
5:
=> 6: $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
7: byebug
8: require 'gitlab_development_kit'
我检查$LOAD_PATH 和File.expand_path('../../lib', __FILE__) 的值:
(byebug) $LOAD_PATH
["/usr/local/Cellar/rbenv/1.1.2/rbenv.d/exec/gem-rehash", ...]
(byebug) File.expand_path('../../lib', __FILE__)
"/Users/richiethomas/Workspace/ThreeEasyPieces/lib"
我输入next来推进调试器,然后重新检查上面的值:
(byebug) next
[2, 11] in /Users/richiethomas/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gitlab-development-kit-0.2.5/bin/gdk
2: require 'yaml'
3: require 'byebug'
4: byebug
5:
6: $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
=> 7: byebug
8: require 'gitlab_development_kit'
9:
10:
11:
(byebug) File.expand_path('../../lib', __FILE__)
"/Users/richiethomas/Workspace/ThreeEasyPieces/lib"
(byebug) $LOAD_PATH
["/Users/richiethomas/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gitlab-development-kit-0.2.5/lib", "/usr/local/Cellar/rbenv/1.1.2/rbenv.d/exec/gem-rehash", ...]
如果File.expand_path('../../lib', __FILE__) 的值确实是"/Users/richiethomas/Workspace/ThreeEasyPieces/lib",那么这就是我希望预先添加到$LOAD_PATH 的值。但相反,RBENV 管理的 gem 版本中的 lib 目录似乎是预先挂起的。这是什么恶魔的魔法? :-)
【问题讨论】: