Skip to content
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

Return 0 for log size when log_data is nil #93

Merged
merged 2 commits into from
Oct 22, 2018
Merged

Conversation

duderman
Copy link
Contributor

Resolves #92

log_size method returns 0 when log_data is nil

@@ -195,6 +195,12 @@ def association(name)
end
# rubocop: enable Metrics/MethodLength

def log_size
return 0 unless log_data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use safe-navigation here:

log_data&.size || 0

WDYT?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be good enough for this case? (nil.to_i -> 0)

log_data&.size.to_i

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling to_i even for an integer involves a method invocation, so using ... || 0 is more efficient

@palkan palkan merged commit c400f22 into palkan:master Oct 22, 2018
@palkan
Copy link
Owner

palkan commented Oct 22, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants