Created
May 28, 2023 17:40
-
-
Save purinkle/0f6fe8d5393c0c64d1fe2e69abe60213 to your computer and use it in GitHub Desktop.
When to use keyword arguments?
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
require "net/http" | |
class HttpWrapper | |
def post(url, body, headers) | |
Net::HTTP.post(URI.parse(url), body, headers) | |
end | |
end | |
url = "https://example.com/path" | |
body = {TEST_KEY: "TEST_VALUE"} | |
headers = {"Authorization" => "Bearer TEST_API_KEY"} | |
@http = HttpWrapper.new | |
@http.post(url, body.to_json, headers).body | |
# or… | |
class HttpWrapper | |
def post(url:, body:, headers:) | |
Net::HTTP.post(URI.parse(url), body, headers) | |
end | |
end | |
url = "https://example.com/path" | |
body = {TEST_KEY: "TEST_VALUE"} | |
headers = {"Authorization" => "Bearer TEST_API_KEY"} | |
@http = HttpWrapper.new | |
@http.post(url:, body: body.to_json, headers:).body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment