Skip to content

Instantly share code, notes, and snippets.

@voidius
Created February 7, 2014 13:18
Show Gist options
  • Save voidius/8862489 to your computer and use it in GitHub Desktop.
Save voidius/8862489 to your computer and use it in GitHub Desktop.
Dynamic generation of Post and Put methods using Module.const_get method
# def post
# def put
[:post, :put].each do |type|
define_method type do |url, content|
uri = URI("http://google.com")
request = Module.const_get("Net::HTTP::#{type.capitalize}").new(uri)
request.body = content
Net::HTTP.start(uri.host, uri.port) { |http| http.request(request) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment