-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Add bang version to OrderedOptions #20208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bang version to OrderedOptions #20208
Conversation
a.foo = nil | ||
a.foo! | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaurish Extra can be removed
Thank you for the pull request.
Not true. There is no rule about this in any place and even if it is a rule, there is cases where it doesn't make sense. I'm having problem to understand where this would be useful, could you give us an example? |
@rafaelfranca Absolutely right, there is no such rule.
Case in point if (slack_url = Rails.application.secrets.slack_url).present?
$slack_notifier = Slack::Notifier.new(slack_url)
else
Rails.logger.error("Unable to find slack_url in secrets.yml")
raise "Unable to find slack_url in secrets.yml"
end gets replaced by $slack_notifier = Slack::Notifier.new(Rails.application.secrets.slack_url!) This is a similar style to What do you think? |
self[name] | ||
bangs = name_string.chomp!('!') | ||
return_value = self[name_string] | ||
bangs && return_value.blank? ? raise(ArgumentError.new("Expected #{name_string} to be defined")) : return_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use if/else
? The line is too long.
PR Updated according to feedback given. |
By: Aditya Sanghi(@asanghi) Gaurish Sharma(gaurish)
/cc @rafaelfranca seems okay now? |
Add bang version to OrderedOptions
* Add a bang version to `ActiveSupport::OrderedOptions` get methods which will raise an `KeyError` if the value is `.blank?` | ||
Before: | ||
|
||
if (slack_url = Rails.application.secrets.slack_url).present?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick: The last closing parens should be deleted.
Every method should have a bang counter-part. if someone uses a bang version & its not defined. it will raise an ArgumentError.
example(normal version)
Rails.application.secrets.big_query
bang version
Rails.application.secrets.big_query!
By:
Aditya Sanghi(@asanghi)
Gaurish Sharma(@gaurish)