Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow-up refactor of #1031 #1034

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1463,21 +1463,16 @@ def truncate_prompt_main(str) # :nodoc:
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
Expand Down
5 changes: 5 additions & 0 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -704,5 +704,10 @@ def inspect # :nodoc:
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