ROA - safe navigation for when nil moleculartestingtype#170
Merged
Conversation
shilpigoeldev
approved these changes
Dec 11, 2025
bshand
reviewed
Dec 12, 2025
| genotype2 = raw_record['genotype2'] | ||
| next if MSH6_DOSAGE_MTYPE.include?(moltesttype) && !exon.scan(/MLPA/i).size.positive? | ||
| next if moltesttype.match?(/dosage/i) && !exon.match?(/MLPA|P003/i) | ||
| next if moltesttype&.match?(/dosage/i) && !exon.match?(/MLPA|P003/i) |
Contributor
There was a problem hiding this comment.
Alternatively, if nil values are allowed, you can write these comparisons as:
next if /dosage/i.match?(moltesttype) && !/MLPA|P003/i.match?(exon)without needing to think about safe navigation.
However, in this case, I can see that having nil inputs for comparison might be a logical error, so maybe it's better to do what's happened here, fail with an exception, and then explicitly flag the exceptions with safe navigation.
irb> /el/.match?('hello')
=> true
irb> /el/.match?('world')
=> false
irb> /el/.match?(nil)
=> false
Collaborator
Author
There was a problem hiding this comment.
Thanks Brian, yes nil values are acceptable in this case, i've amended the code to you suggested first option in a new PR #171
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added in safe navigation operator to handle where molecular testing type is genuinly nil in the data.
All local tests passing successfully