Ruby 中的 'use ClassName' 是什么(相对于包含、要求、加载)
What is 'use ClassName' in Ruby (vs include, require, load)
use SomeClassName
在 Ruby 中做什么?
在迁移 'flat/classic' Sinatra 应用程序以对每个控制器使用单独的 类 的过程中,我看到一篇博客文章建议先 require
然后 use
类.
#app.rb a Sinatra classic app that formerly had all the routes in app.rb, now moved to separate controller classes
...
require "./app/controllers/foo_controller.rb"
require "./app/controllers/bar_controller.rb"
use Foo # a class with a set of routes
use Bar # a class with a set of routes
...
多年以来,我一直以某种方式相当高效地使用 Ruby、Sinatra 和 Rails,而无需使用 use
语句,并添加 [=15= 这样的常用词] 到任何 google 查询都不会缩小搜索范围。
What is 'use ClassName' in Ruby (vs include, require, load)
在ruby中这没有任何意义。它是 sinatra API.
的一部分
如果那些控制器文件仍然包含 "classic app" 风格的代码,您就不需要在这里使用 use
。简单地要求他们就可以了。
但由于它们现在在技术上是独立的 Sinatra 应用程序(据我猜测文件的内容),您需要将它们安装在主应用程序中。这是通过将应用程序(及其路由器)注册为中间件来完成的。
use SomeClassName
在 Ruby 中做什么?
在迁移 'flat/classic' Sinatra 应用程序以对每个控制器使用单独的 类 的过程中,我看到一篇博客文章建议先 require
然后 use
类.
#app.rb a Sinatra classic app that formerly had all the routes in app.rb, now moved to separate controller classes
...
require "./app/controllers/foo_controller.rb"
require "./app/controllers/bar_controller.rb"
use Foo # a class with a set of routes
use Bar # a class with a set of routes
...
多年以来,我一直以某种方式相当高效地使用 Ruby、Sinatra 和 Rails,而无需使用 use
语句,并添加 [=15= 这样的常用词] 到任何 google 查询都不会缩小搜索范围。
What is 'use ClassName' in Ruby (vs include, require, load)
在ruby中这没有任何意义。它是 sinatra API.
的一部分如果那些控制器文件仍然包含 "classic app" 风格的代码,您就不需要在这里使用 use
。简单地要求他们就可以了。
但由于它们现在在技术上是独立的 Sinatra 应用程序(据我猜测文件的内容),您需要将它们安装在主应用程序中。这是通过将应用程序(及其路由器)注册为中间件来完成的。