Ruby __dir__ 可以简化代码

chenge · 2017年08月04日 · 最后由 dfzy5566 回复于 2017年08月04日 · 2122 次阅读

不错,可以去掉两点。

File.expand_path('../application.rb', __FILE__)


File.expand_path('application.rb', __dir__)

https://bogdanvlviv.github.io/posts/ruby/with-__dir__-we-can-restore-order-in-the-universe.html

机智,我都是这样的:

Dir[File.expand_path('./utility/*.rb', File.dirname(__FILE__))].each {|file| require file }
需要 登录 后方可回复, 如果你还没有账号请 注册新账号