mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Try not to register the exact same measuring method twice
cc66b5573e
This commit is contained in:
parent
2c752ff930
commit
167dc37632
2 changed files with 14 additions and 4 deletions
|
@ -20,11 +20,11 @@ module IRB
|
||||||
when :on
|
when :on
|
||||||
IRB.conf[:MEASURE] = true
|
IRB.conf[:MEASURE] = true
|
||||||
added = IRB.set_measure_callback(type, arg)
|
added = IRB.set_measure_callback(type, arg)
|
||||||
puts "#{added[0]} is added."
|
puts "#{added[0]} is added." if added
|
||||||
else
|
else
|
||||||
IRB.conf[:MEASURE] = true
|
IRB.conf[:MEASURE] = true
|
||||||
added = IRB.set_measure_callback(type, arg)
|
added = IRB.set_measure_callback(type, arg)
|
||||||
puts "#{added[0]} is added."
|
puts "#{added[0]} is added." if added
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,8 +158,18 @@ module IRB # :nodoc:
|
||||||
else
|
else
|
||||||
added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
|
added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
|
||||||
end
|
end
|
||||||
IRB.conf[:MEASURE_CALLBACKS] << added if added
|
if added
|
||||||
added
|
found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] }
|
||||||
|
if found
|
||||||
|
# already added
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
IRB.conf[:MEASURE_CALLBACKS] << added if added
|
||||||
|
added
|
||||||
|
end
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def IRB.unset_measure_callback(type = nil)
|
def IRB.unset_measure_callback(type = nil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue