[英]Ruby, load classes and methods from different script
So I'm still a bit confused at how load paths work basically I have a file structure like:所以我仍然对加载路径的工作方式感到有些困惑,基本上我有一个文件结构,如:
my_app
bin
my_bin
lib
processor.rb
So the problem is the the file my_bin
is a bin file (in ruby) that is supposed to call a class and method in processor.rb
所以问题是文件my_bin
是一个 bin 文件(在 ruby 中),它应该调用processor.rb
的类和方法
The bin file requires gems and other stuff at the top, but how can I have the classes in processor.rb
loaded? bin 文件需要顶部的 gems 和其他东西,但是如何加载processor.rb
的类?
in 1.9.2 you can do:在 1.9.2 你可以这样做:
require_relative '../lib/processor'
in 1.8.7 you can do:在 1.8.7 中,您可以执行以下操作:
$: << "/absolute/path/to_parent_of_lib/lib"
require 'processor'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.