-
-
Save paulcsmith/b26cfcaf82c4ff87e9dcc46f6c42e48b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Responder | |
@body = "" | |
def html | |
if true | |
@body = yield | |
end | |
end | |
def js | |
if false | |
@body = yield | |
end | |
end | |
def respond_to | |
yield self | |
@body | |
end | |
end | |
body = Responder.new.respond_to do |format| | |
format.html { "html" } | |
format.js { "js" } | |
end | |
def handle_response(response : String) | |
p response | |
end | |
handle_response(body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would it be interesting to have type-safe responders? Like, make incoming requests subclasses of
LuckyRequest
based on MIME type (JSONRequest, HTMLRequest) and havedef index( r : JSONRequest)
, etc?I guess you'd want to share code between the different actions, though...