"if development?" Jump Start Sinatra book and environment detection method call

In both page 8 and page 67, the contruction if development? is used. On page 67, in a setting within a route, like this:

get '/environment' do
  if development?
  elsif production?
  elsif test?
    "Who knows what environment you're in!"

Within my app I was not able to get this running, this resulted in

NoMethodError at /environment
undefined method `development?'`

I found that it works if I prefix .development (and the other envs) with Sinatra::Base

But I’m trying to figure out how/why?

If I start my program by defining it as a class like this:

class MyApp < Sinatra::Base

… I think it sort of makes sense that I have to refer to Sintatra::Base.development?

But if this app is just plain route defs etc. after require ‘sinatra’, I’m having trouble grasping why, and how to run the code from the book unmodified?

(Yes, I’m a bit of a n00b.) :sunglasses:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.