Warn and do nothing if block is passed to measure command#813
Merged
tompng merged 1 commit intoruby:masterfrom Dec 13, 2023
Merged
Warn and do nothing if block is passed to measure command#813tompng merged 1 commit intoruby:masterfrom
tompng merged 1 commit intoruby:masterfrom
Conversation
tompng
commented
Dec 13, 2023
| puts "#{added[0]} is added." if added | ||
| else | ||
| if block_given? | ||
| IRB.conf[:MEASURE] = true |
Member
Author
There was a problem hiding this comment.
Changing IRB.conf[:MEASURE] is moved to IRB.set_measure_calback and IRB.unset_measure_calback.
This refactor also makes IRB.set_measure_calback do end to be a complete alternative of measure do end
tompng
commented
Dec 13, 2023
| type_sym = type.upcase.to_sym | ||
| IRB.conf[:MEASURE_CALLBACKS].reject!{ |t, | t == type_sym } | ||
| end | ||
| IRB.conf[:MEASURE] = nil if IRB.conf[:MEASURE_CALLBACKS].empty? |
Member
Author
There was a problem hiding this comment.
measure :off, :measure_type had a bug
# lib/irb/cmd/measure.rb:20
when :off
IRB.conf[:MEASURE] = nil
IRB.unset_measure_callback(arg)That disables all measure even if arg is specified.
irb> measure :foo
"FOO" is added
irb> measure :bar
"BAR" is added
irb> measure :off, :foo
# removes :foo and turns all measure off
irb> 42
# no measure
irb> measure
"TIME" added. (and BAR is re-enabled)
2f79d19 to
4bda1a3
Compare
tompng
commented
Dec 13, 2023
| when :on | ||
| IRB.conf[:MEASURE] = true | ||
| added = IRB.set_measure_callback(type, arg) | ||
| added = IRB.set_measure_callback(arg) |
Member
Author
There was a problem hiding this comment.
set_measure_callback(:on, arg) had no effect (unless IRB.conf[:MEASURE_PROC][:ON] is set)
This will fix a bug that measure :on was enabling TIME without showing "TIME" is added. message.
This will also allow measure :on, :foobar, an opposite of measure :off, :foobar
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.
Ruby 3.3 is a good opportunity to add a warning message for measure command with block.
(Although, I think no one reads the warning because (maybe) no one use it.)
I searched the commit that added measure with block but it had no desciption. #183 #184
Measure command with block is
measure{heavy_logic_to_be_measured}.Usage of measure with block was
Alternative API of measure with block
Alternative workaround for measure with block
Measure with block will register a session-only measure method that you don't need to write to `.irbrc`` for reusing. For this purpose, these workaround is enough and easier than using measure command with block. That's why I think no one use it.