Created
February 7, 2014 13:18
-
-
Save voidius/8862489 to your computer and use it in GitHub Desktop.
Dynamic generation of Post and Put methods using Module.const_get method
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
# 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