Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active October 5, 2016 14:05
Show Gist options
  • Save paulcsmith/8eb041acd4efab838d196e7943a76570 to your computer and use it in GitHub Desktop.
Save paulcsmith/8eb041acd4efab838d196e7943a76570 to your computer and use it in GitHub Desktop.
# 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