-
Notifications
You must be signed in to change notification settings - Fork 121
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
Warn and do nothing if block is passed to measure command #813
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,32 +12,29 @@ def initialize(*args) | |
super(*args) | ||
end | ||
|
||
def execute(type = nil, arg = nil, &block) | ||
def execute(type = nil, arg = nil) | ||
# Please check IRB.init_config in lib/irb/init.rb that sets | ||
# IRB.conf[:MEASURE_PROC] to register default "measure" methods, | ||
# "measure :time" (abbreviated as "measure") and "measure :stackprof". | ||
|
||
if block_given? | ||
warn 'Configure IRB.conf[:MEASURE_PROC] to add custom measure methods.' | ||
return | ||
end | ||
|
||
case type | ||
when :off | ||
IRB.conf[:MEASURE] = nil | ||
IRB.unset_measure_callback(arg) | ||
when :list | ||
IRB.conf[:MEASURE_CALLBACKS].each do |type_name, _, arg_val| | ||
puts "- #{type_name}" + (arg_val ? "(#{arg_val.inspect})" : '') | ||
end | ||
when :on | ||
IRB.conf[:MEASURE] = true | ||
added = IRB.set_measure_callback(type, arg) | ||
added = IRB.set_measure_callback(arg) | ||
puts "#{added[0]} is added." if added | ||
else | ||
if block_given? | ||
IRB.conf[:MEASURE] = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing |
||
added = IRB.set_measure_callback(&block) | ||
puts "#{added[0]} is added." if added | ||
else | ||
IRB.conf[:MEASURE] = true | ||
added = IRB.set_measure_callback(type, arg) | ||
puts "#{added[0]} is added." if added | ||
end | ||
added = IRB.set_measure_callback(type, arg) | ||
puts "#{added[0]} is added." if added | ||
end | ||
nil | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,7 @@ def IRB.set_measure_callback(type = nil, arg = nil, &block) | |
added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg] | ||
end | ||
if added | ||
IRB.conf[:MEASURE] = true | ||
found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] } | ||
if found | ||
# already added | ||
|
@@ -235,6 +236,7 @@ def IRB.unset_measure_callback(type = nil) | |
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
# 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.
|
||
end | ||
|
||
def IRB.init_error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ofmeasure :off, :foobar