Paul McKellar

WUT. SVAngel. Square founding team. Programmer.

Sinatra Vs Ruby Expectations

In ruby, the LAST definition of a function is the one that executes.

def test;
puts "first";
end

def test;
puts "last";
end

test # => last

In Sinatra, the first defined route executes

get "/test" do;
puts "first";
end

get "/test" do;
puts "last";
end
GET /test # => first

Rails kinda does the same thing regarding routes (first declared executes). But because of rails’ terse-ness regarding routes I expected it. I see everything on one page for routes, and assume top executes first. With Sinatra, and ruby in general, I expected the last definition to override the first.

(Sinatra wins in terseness in every other regard vs rails and I understand why Sinatra does this, now)