从实例方法中获取sinatra环境

时间:2011-11-19 05:10:03

标签: ruby sinatra

确定环境的正确方法是什么?现在我正在使用:

class Main < Sinatra::Base
    get '/' do
        puts self.class.development?
        puts self.class.production?
    end
end

但这似乎不对。

3 个答案:

答案 0 :(得分:32)

我会使用Sinatra::Base.development?Sinatra::Base.production?,因为这是方法的来源。

答案 1 :(得分:19)

self.class.development?实际应该有效。这些都适用于Sinatra 1.3.1:

class Main < Sinatra::Base
  get '/' do
    puts Main.development?
    puts self.class.development?
    puts settings.development?
    puts settings.environment == :development
  end
end

答案 2 :(得分:0)

puts Sinatra::Application.environment

#=> production (or test, development)