Questions tagged «ruby-1.8»

11
Ruby:require vs require_relative-解决在Ruby <1.9.2和> = 1.9.2中运行的最佳方法
如果我想require在Ruby中创建一个相对文件并且希望它在1.8.x和&gt; = 1.9.2中都可以工作,那么最佳实践是什么? 我看到一些选择: 只是去做$LOAD_PATH &lt;&lt; '.',忘记一切 做 $LOAD_PATH &lt;&lt; File.dirname(__FILE__) require './path/to/file' 检查是否RUBY_VERSION&lt;1.9.2,然后定义require_relative为,然后在需要的地方require使用require_relative 检查是否require_relative已经存在(如果存在),请尝试像以前一样进行 使用怪异的结构,例如-they,它们似乎无法完全在Ruby 1.9中工作,因为,例如:require File.join(File.dirname(__FILE__), 'path/to/file')$ cat caller.rb require File.join(File.dirname(__FILE__), 'path/to/file') $ cat path/to/file.rb puts 'Some testing' $ ruby caller Some testing $ pwd /tmp $ ruby /tmp/caller Some testing $ ruby tmp/caller tmp/caller.rb:1:in 'require': no such …
153 ruby  ruby-1.9  ruby-1.8 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.