@@ -569,7 +569,6 @@ def show_locals pat
569
569
end
570
570
571
571
def show_ivars pat , expr = nil
572
-
573
572
if expr && !expr . empty?
574
573
_self = frame_eval ( expr ) ;
575
574
elsif _self = current_frame &.self
@@ -585,18 +584,39 @@ def show_ivars pat, expr = nil
585
584
end
586
585
end
587
586
588
- def show_consts pat , only_self : false
589
- if s = current_frame &.self
587
+ def iter_consts c , names = { }
588
+ c . constants ( false ) . sort . each { |name |
589
+ next if names . has_key? name
590
+ names [ name ] = nil
591
+ begin
592
+ value = c . const_get ( name )
593
+ rescue Exception => e
594
+ value = e
595
+ end
596
+ yield name , value
597
+ }
598
+ end
599
+
600
+ def get_consts expr = nil , only_self : false , &block
601
+ if expr && !expr . empty?
602
+ _self = frame_eval ( expr )
603
+ if M_KIND_OF_P . bind_call ( _self , Module )
604
+ iter_consts _self , &block
605
+ return
606
+ else
607
+ raise "#{ _self . inspect } (by #{ expr } ) is not a Module."
608
+ end
609
+ elsif _self = current_frame &.self
590
610
cs = { }
591
- if M_KIND_OF_P . bind_call ( s , Module )
592
- cs [ s ] = :self
611
+ if M_KIND_OF_P . bind_call ( _self , Module )
612
+ cs [ _self ] = :self
593
613
else
594
- s = M_CLASS . bind_call ( s )
595
- cs [ s ] = :self unless only_self
614
+ _self = M_CLASS . bind_call ( _self )
615
+ cs [ _self ] = :self unless only_self
596
616
end
597
617
598
618
unless only_self
599
- s . ancestors . each { |c | break if c == Object ; cs [ c ] = :ancestors }
619
+ _self . ancestors . each { |c | break if c == Object ; cs [ c ] = :ancestors }
600
620
if b = current_frame &.binding
601
621
b . eval ( '::Module.nesting' ) . each { |c | cs [ c ] = :nesting unless cs . has_key? c }
602
622
end
@@ -605,20 +625,17 @@ def show_consts pat, only_self: false
605
625
names = { }
606
626
607
627
cs . each { |c , _ |
608
- c . constants ( false ) . sort . each { |name |
609
- next if names . has_key? name
610
- names [ name ] = nil
611
- begin
612
- value = c . const_get ( name )
613
- rescue Exception => e
614
- value = e
615
- end
616
- puts_variable_info name , value , pat
617
- }
628
+ iter_consts c , names , &block
618
629
}
619
630
end
620
631
end
621
632
633
+ def show_consts pat , expr = nil , only_self : false
634
+ get_consts expr , only_self : only_self do |name , value |
635
+ puts_variable_info name , value , pat
636
+ end
637
+ end
638
+
622
639
SKIP_GLOBAL_LIST = %i[ $= $KCODE $-K $SAFE ] . freeze
623
640
def show_globals pat
624
641
global_variables . sort . each { |name |
@@ -1105,7 +1122,8 @@ def wait_next_action_
1105
1122
1106
1123
when :consts
1107
1124
pat = args . shift
1108
- show_consts pat
1125
+ expr = args . shift
1126
+ show_consts pat , expr
1109
1127
1110
1128
when :globals
1111
1129
pat = args . shift
0 commit comments