Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active October 5, 2016 14:05
# Instead of this...
before_all "/foo" do |env|
puts "Setting response content type"
env.response.content_type = "application/json"
end
# Can I do this..
before_all "/foo", &set_json # where &set_json capture the set_json method
get "/foo" do |env|
puts env.response.content_type # => "application/json"
{"name": "Kemal"}.to_json
end
def set_json(env)
puts "Setting response content type"
env.response.content_type = "application/json"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment