[ruby/irb] Move main object's safe call logic to Context
(https://github.com/ruby/irb/pull/1034) https://github.com/ruby/irb/commit/9750fa23cc
This commit is contained in:
parent
743a31d639
commit
2df2e868bc
@ -1463,21 +1463,16 @@ module IRB
|
||||
end
|
||||
end
|
||||
|
||||
def basic_object_safe_main_call(method)
|
||||
main = @context.main
|
||||
Object === main ? main.__send__(method) : Object.instance_method(method).bind_call(main)
|
||||
end
|
||||
|
||||
def format_prompt(format, ltype, indent, line_no) # :nodoc:
|
||||
format.gsub(/%([0-9]+)?([a-zA-Z%])/) do
|
||||
case $2
|
||||
when "N"
|
||||
@context.irb_name
|
||||
when "m"
|
||||
main_str = basic_object_safe_main_call(:to_s) rescue "!#{$!.class}"
|
||||
main_str = @context.safe_method_call_on_main(:to_s) rescue "!#{$!.class}"
|
||||
truncate_prompt_main(main_str)
|
||||
when "M"
|
||||
main_str = basic_object_safe_main_call(:inspect) rescue "!#{$!.class}"
|
||||
main_str = @context.safe_method_call_on_main(:inspect) rescue "!#{$!.class}"
|
||||
truncate_prompt_main(main_str)
|
||||
when "l"
|
||||
ltype
|
||||
|
@ -704,5 +704,10 @@ module IRB
|
||||
def local_variables # :nodoc:
|
||||
workspace.binding.local_variables
|
||||
end
|
||||
|
||||
def safe_method_call_on_main(method_name)
|
||||
main_object = main
|
||||
Object === main_object ? main_object.__send__(method_name) : Object.instance_method(method_name).bind_call(main_object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user