This is a more focused version of a previous question of mine around Sinatra's handling of route methods.
From my understanding of the source code Sinatra takes the method block within the route, and passes a new method containing the same body out i.e:
get "some/url" do
return "Hello World" # this gets taken out
end
So in this example the method body seems to get copied into a new method which is applied to the Sinatra object. I am just wondering why this happens, I tried going on their IRC channel but no one was there, and the mailing list is not that busy.
The main bulk of the source code that I am talking about in their framework is within base.rb around line 1180:
def generate_method(method_name, &block)
define_method(method_name, &block)
method = instance_method method_name
remove_method method_name
method
end
So is there any specific reason why they do this and not just reference the method itself?
The reason I ask this question is because the way Sinatra currently handles this it makes it impossible to have a method that has knowledge outside of itself, and breaks a classes encapsulation by just taking a single method without context.