@@ -563,11 +563,11 @@ def eval_input
563
563
if IRB . conf [ :MEASURE ] && IRB . conf [ :MEASURE_CALLBACKS ] . empty?
564
564
IRB . set_measure_callback
565
565
end
566
- # Assignment expression check should be done before @context.evaluate to handle code like `a /2#/ if false; a = 1`
566
+ # Assignment expression check should be done before evaluate_line to handle code like `a /2#/ if false; a = 1`
567
567
is_assignment = assignment_expression? ( line )
568
568
if IRB . conf [ :MEASURE ] && !IRB . conf [ :MEASURE_CALLBACKS ] . empty?
569
569
result = nil
570
- last_proc = proc { result = @context . evaluate ( line , line_no , exception : exc ) }
570
+ last_proc = proc { result = evaluate_line ( line , line_no , exception : exc ) }
571
571
IRB . conf [ :MEASURE_CALLBACKS ] . inject ( last_proc ) { |chain , item |
572
572
_name , callback , arg = item
573
573
proc {
@@ -578,7 +578,7 @@ def eval_input
578
578
} . call
579
579
@context . set_last_value ( result )
580
580
else
581
- @context . evaluate ( line , line_no , exception : exc )
581
+ evaluate_line ( line , line_no , exception : exc )
582
582
end
583
583
if @context . echo?
584
584
if is_assignment
@@ -604,6 +604,23 @@ def eval_input
604
604
end
605
605
end
606
606
607
+ def evaluate_line ( line , line_no , exception : nil )
608
+ # Transform a non-identifier alias (@, $) or keywords (next, break)
609
+ command , args = line . split ( /\s / , 2 )
610
+ if original = @context . command_aliases [ command . to_sym ]
611
+ line = line . gsub ( /\A #{ Regexp . escape ( command ) } / , original . to_s )
612
+ command = original
613
+ end
614
+
615
+ # Hook command-specific transformation
616
+ command_class = ExtendCommandBundle . load_command ( command )
617
+ if command_class &.respond_to? ( :transform_args )
618
+ line = "#{ command } #{ command_class . transform_args ( args ) } "
619
+ end
620
+
621
+ @context . evaluate ( line , line_no , exception : exception )
622
+ end
623
+
607
624
def convert_invalid_byte_sequence ( str , enc )
608
625
str . force_encoding ( enc )
609
626
str . scrub { |c |
0 commit comments