[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
|
||||||
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:
|
def format_prompt(format, ltype, indent, line_no) # :nodoc:
|
||||||
format.gsub(/%([0-9]+)?([a-zA-Z%])/) do
|
format.gsub(/%([0-9]+)?([a-zA-Z%])/) do
|
||||||
case $2
|
case $2
|
||||||
when "N"
|
when "N"
|
||||||
@context.irb_name
|
@context.irb_name
|
||||||
when "m"
|
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)
|
truncate_prompt_main(main_str)
|
||||||
when "M"
|
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)
|
truncate_prompt_main(main_str)
|
||||||
when "l"
|
when "l"
|
||||||
ltype
|
ltype
|
||||||
|
@ -704,5 +704,10 @@ module IRB
|
|||||||
def local_variables # :nodoc:
|
def local_variables # :nodoc:
|
||||||
workspace.binding.local_variables
|
workspace.binding.local_variables
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user