Where is the 'get' method defined? And how is it called on no object?
require 'sinatra'
get '/hi' do
"Hello World!"
end
The example from the http://www.sinatrarb.com/ homepage.
Where is the 'get' method defined? And how is it called on no object?
require 'sinatra'
get '/hi' do
"Hello World!"
end
The example from the http://www.sinatrarb.com/ homepage.
You are not calling anything on "no object" but calling require 'sinatra'
on Object
and this loads the library, if it is available to be loaded, which gives you the method get
, among other things.
Where get is defined is in the Sinatra gem, in the lib folder, in a file called base.rb and this code is presumably 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
In order to understand what is going on here, you need a fundamental understanding of how Ruby works. That is a bit more than what can or should be answered in an answer here.