Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Created April 24, 2017 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/b26cfcaf82c4ff87e9dcc46f6c42e48b to your computer and use it in GitHub Desktop.
Save paulcsmith/b26cfcaf82c4ff87e9dcc46f6c42e48b to your computer and use it in GitHub Desktop.
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)
@sardaukar
Copy link

Would it be interesting to have type-safe responders? Like, make incoming requests subclasses of LuckyRequest based on MIME type (JSONRequest, HTMLRequest) and have def index( r : JSONRequest), etc?

I guess you'd want to share code between the different actions, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment