request_url ||= URI_FORMATS[:home_page] % {
base_uri: AppConfig.test_api['base_url'],
end_point: AppConfig.test_api['end_points']['home_page'],
client_id: AppConfig.test_api['client_id'],
}
I am getting Favor format over String#% rubocop error for this. Any idea how to resolve this. I just gone through the cause of the error here
https://quynhcodes.wordpress.com/2017/03/29/string-interpolation-in-ruby/
But I am not using any string interpolation here.
So how can we solve this issue.?
First of all, this is not about string interpolation, but about string formatting. The RuboCop Ruby style guide says:
Favor the use of
sprintf
and its aliasformat
over the fairly crypticString#%
method.
This would mean changing
request_url ||= URI_FORMATS[:home_page] % {
base_uri: AppConfig.test_api['base_url'],
end_point: AppConfig.test_api['end_points']['home_page'],
client_id: AppConfig.test_api['client_id'],
}
to
request_url ||= format(
URI_FORMATS[:home_page],
base_uri: AppConfig.test_api['base_url'],
end_point: AppConfig.test_api['end_points']['home_page'],
client_id: AppConfig.test_api['client_id'],
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With