使用Ruby + Webrick + Sinatra,'开发'在哪里?(With Ruby + Webrick + Sinatra, where does 'develo

编程入门 行业动态 更新时间:2024-10-27 06:29:44
使用Ruby + Webrick + Sinatra,'开发'在哪里?(With Ruby + Webrick + Sinatra, where does 'development?' method come from?)

使用ruby + webrick + sinatra时,'开发模式'的概念来自哪里?

require 'sinatra' require 'sinatra/reloader' get '/test' do development?.to_s end

当我通过'ruby test.rb -p 3000'运行上面的应用程序时http:// localhost:3000 / test返回“true”...但为什么它返回true? 开发模式是ruby,webrick,rack还是sinatra概念? 此外,特定于非特定于轨道的方式记录此功能吗? 我发现很多人都参考了开发模式的概念,但我一直惊讶于找到相关信息的难度......也许我只是没有谷歌正确的关键词......

Where does the concept of 'development mode' come from when using ruby + webrick + sinatra?

require 'sinatra' require 'sinatra/reloader' get '/test' do development?.to_s end

When I run the above app by 'ruby test.rb -p 3000' http://localhost:3000/test returns "true" ... but why does it return true? Is development mode a ruby, webrick, rack or sinatra concept? Also, is this functionality documented anywhere in particular in a non-rails specific manner? I'm finding many people reference the concept of development mode, but I've been surprised by how hard it has been to find relevant information ... maybe I'm just not google-ing the right keywords ...

最满意答案

Sinatra的源代码(base.rb)显示了这3个定义:

def development?; environment == :development end def production?; environment == :production end def test?; environment == :test end

因此,这些真/假方法基于设置环境。 Sinatra默认在开发模式下运行,除非你另外告诉它(当你启动Sinatra应用程序时,你会看到像

== Sinatra/1.2.6 has taken the stage on 4567 for **development** with backup from WEBrick".

要告诉它在生产中运行,你会这样做:

ruby test.rb -p 3000 -e production

Sinatra's source code (base.rb) shows these 3 definitions:

def development?; environment == :development end def production?; environment == :production end def test?; environment == :test end

So those true/false methods are based on the set environment. Sinatra defaults to run in development mode unless you tell it otherwise (when you start a Sinatra app, you'll see something like

== Sinatra/1.2.6 has taken the stage on 4567 for **development** with backup from WEBrick".

To tell it to run in production, you would do this:

ruby test.rb -p 3000 -e production

更多推荐

本文发布于:2023-07-28 23:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Webrick   Ruby   Sinatra   method   development

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!