Ruby __dir__ 可以简化代码

chenge · August 04, 2017 · Last by dfzy5566 replied at August 04, 2017 · 2123 hits

不错,可以去掉两点。

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 }
You need to Sign in before reply, if you don't have an account, please Sign up first.