How does the example of Sinatra hello to the world work?

Where is the get method defined? And what is it called without an object?

require 'sinatra'

get '/hi' do
  "Hello World!"
end

Example from http://www.sinatrarb.com/ .

+4
source share
1 answer

You don't call anything “no object”, but you call require 'sinatra'on Object, and this loads the library if it is available for download, which gives, among other things, a method get.

Where get is defined is in the Sinatra stone in the lib folder in the base.rb file, and this code is supposedly located on your computer.

# Defining a `GET` handler also automatically defines
# a `HEAD` handler.
def get(path, opts = {}, &block)
  conditions = @conditions.dup
  route('GET', path, opts, &block)

  @conditions = conditions
  route('HEAD', path, opts, &block)
end

, , , Ruby. , .

+4

All Articles