Ruby: require vs require_relative - best practice to workaround running in both Ruby <1.9.2 and >=1.9.2
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the best practice if I want to require a relative file in Ruby and I want it to work in both 1.8.x and >=1.9.2? I see a few options: just do $LOAD_PATH and forget everything do $LOAD_PATH require './path/to/file' check if RUBY_VERSION require_relative as require , use require_relative everywhere where it's needed afterwards check if require_relative already exists, if it does, try to proceed as in previous case use weird constructions such as require File.join(File.dirname(__FILE__), 'path/to/file') - alas they don't seem to work in