In Rails 4.2.5, in app/config/application.rb, I noticed this piece of code at the top of the file:
require File.expand_path('../boot', __FILE__)
Q1: Isn't this the same as this?:
require_relative('boot')
Q2: If these two are the same does anybody have any idea why rails uses the former code and not the latter? It seems like the latter bit of code is shorter and clearer and would therefore be preferable.
Great question. It's probably just a holdover from when Rails supported Ruby 1.8.7, as require_relative wasn't introduced until Ruby 1.9. But since 1.8.7 support was dropped as of Rails 4.0, there's really no reason why require_relative couldn't be used instead. My guess is that no one has thought to change it in the intervening years, since it works as is. Also, I'm not sure if making the Rails code base clearer and easier to understand is at all a priority for the Rails core team.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With