In the Sinatra README, there is a section called Custom Route Matchers with the following example:
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
end
def match(str)
@captures unless @except === str
end
end
def all_but(pattern)
AllButPattern.new(pattern)
end
get all_but("/index") do
# ...
end
Would anyone be helpful enough to talk me through how this works? The bit I'm not sure about is why the example has the Match
struct and what captures
are. The user can't set the @captures
instance variable, just the @except
one; so how is captures
used?