@@ -3,10 +3,8 @@ module IRB
33
44 module Command
55 class Measure < Base
6- include RubyArgsExtractor
7-
86 category "Misc"
9- description "`measure` enables the mode to measure processing time. `measure : off` disables it."
7+ description "`measure` enables the mode to measure processing time. `measure off` disables it."
108
119 def initialize ( *args )
1210 super ( *args )
@@ -17,28 +15,43 @@ def execute(arg)
1715 warn 'Configure IRB.conf[:MEASURE_PROC] to add custom measure methods.'
1816 return
1917 end
20- args , kwargs = ruby_args ( arg )
21- execute_internal ( *args , **kwargs )
18+
19+ if arg . empty?
20+ execute_internal ( nil , nil )
21+ elsif arg . start_with? ':'
22+ # Legacy style `measure :sym`, `measure :sym, :sym`
23+ type , arg_val = arg . split ( /,\s */ , 2 ) . map { |v | v . sub ( /\A :/ , '' ) }
24+ warn "`measure #{ arg } ` is deprecated. Please use `measure #{ [ type , arg_val ] . compact . join ( ' ' ) } ` instead."
25+ execute_internal ( type . to_sym , arg_val )
26+ else
27+ type , arg_val = arg . split ( /\s +/ , 2 )
28+ execute_internal ( type &.to_sym , arg_val )
29+ end
2230 end
2331
24- def execute_internal ( type = nil , arg = nil )
32+ def execute_internal ( type , arg )
2533 # Please check IRB.init_config in lib/irb/init.rb that sets
2634 # IRB.conf[:MEASURE_PROC] to register default "measure" methods,
27- # "measure : time" (abbreviated as "measure") and "measure : stackprof".
35+ # "measure time" (abbreviated as "measure") and "measure stackprof".
2836
2937 case type
3038 when :off
31- IRB . unset_measure_callback ( arg )
39+ IRB . unset_measure_callback ( arg &. to_sym )
3240 when :list
3341 IRB . conf [ :MEASURE_CALLBACKS ] . each do |type_name , _ , arg_val |
3442 puts "- #{ type_name } " + ( arg_val ? "(#{ arg_val . inspect } )" : '' )
3543 end
36- when :on
37- added = IRB . set_measure_callback ( arg )
38- puts "#{ added [ 0 ] } is added." if added
3944 else
40- added = IRB . set_measure_callback ( type , arg )
41- puts "#{ added [ 0 ] } is added." if added
45+ type , arg = arg &.to_sym , nil if type == :on
46+
47+ measure_methods = IRB . conf [ :MEASURE_PROC ] . keys . map ( &:downcase )
48+ if type && !measure_methods . include? ( type )
49+ puts "Measure method `#{ type } ` not found."
50+ puts "Available measure methods: %w[#{ measure_methods . join ( ' ' ) } ]."
51+ else
52+ added = IRB . set_measure_callback ( type &.to_sym , arg )
53+ puts "#{ added [ 0 ] } is added." if added
54+ end
4255 end
4356 nil
4457 end
0 commit comments