Skip to content

Commit

Permalink
Merge pull request #154 from aycabta/try-not-to-register-the-exact-sa…
Browse files Browse the repository at this point in the history
…me-measuring-method-twice

Try not to register the exact same measuring method twice
  • Loading branch information
aycabta committed Dec 24, 2020
2 parents e737aac + cc66b55 commit b5e1be6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/irb/cmd/measure.rb
Expand Up @@ -20,11 +20,11 @@ def execute(type = nil, arg = nil)
when :on
IRB.conf[:MEASURE] = true
added = IRB.set_measure_callback(type, arg)
puts "#{added[0]} is added."
puts "#{added[0]} is added." if added
else
IRB.conf[:MEASURE] = true
added = IRB.set_measure_callback(type, arg)
puts "#{added[0]} is added."
puts "#{added[0]} is added." if added
end
nil
end
Expand Down
14 changes: 12 additions & 2 deletions lib/irb/init.rb
Expand Up @@ -158,8 +158,18 @@ def IRB.set_measure_callback(type = nil, arg = nil)
else
added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
end
IRB.conf[:MEASURE_CALLBACKS] << added if added
added
if 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

def IRB.unset_measure_callback(type = nil)
Expand Down

0 comments on commit b5e1be6

Please sign in to comment.