Repository navigation
Refactor: Reduce duplicated code in measure.rb - #1250
Conversation
| when :on | ||
| added = IRB.set_measure_callback(arg) | ||
| puts "#{added[0]} is added." if added | ||
| measure_callback = IRB.set_measure_callback(arg) |
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 addedThere 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
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.
774aff8 to
d0ba6c1
Compare
closes #1249
Why
puts "#{added[0]} is added."was written twice in the codeSolution
private method to encapsulate the logic and prevent duplication.