Refactor: Reduce duplicated code in measure.rb - #1250
Merged
tompng merged 1 commit intoSep 8, 2026
Merged
Conversation
tompng
reviewed
Sep 8, 2026
| when :on | ||
| added = IRB.set_measure_callback(arg) | ||
| puts "#{added[0]} is added." if added | ||
| measure_callback = IRB.set_measure_callback(arg) |
Member
There was a problem hiding this comment.
It is added in IRB.conf[:MEASURE_CALLBACKS], so it's an internal expression of type, callback, and measuring argument, but I'm not sure if the whole tuple is really called measure_callback.
Currently, the internal structure of set_measure_callback is only leaked to here. Passing internal structure to another method will increase the leak range.
How about something like this?
# Leave unrelated part
added = IRB.set_measure_callback(arg)
# display_added_message(type) needs type, will print a message,
# and nil-check is done in here, the caller site, not in display method.
display_added_message(added[0]) if added
Contributor
Author
There was a problem hiding this comment.
Thanks for the feedback.
Good to know about the leak, that makes sense to me, thanks for spending time pointing that out.
I will address that now
Contributor
Author
There was a problem hiding this comment.
@tompng comment addressed. Thank you once again.
puts "#{added[0]} is added." was typed twice in the code.
GabrielLidenor
force-pushed
the
refactor-callback-message-measure
branch
from
September 8, 2026 13:31
774aff8 to
d0ba6c1
Compare
tompng
approved these changes
Sep 8, 2026
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.
closes #1249
Why
puts "#{added[0]} is added."was written twice in the codeSolution
private method to encapsulate the logic and prevent duplication.