Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide pry scope?

Sometimes when I open a binding.pry session in a spec it shows me a too long scope in the shell like the following and takes all the shell line:

[3] pry(#<RSpec::ExampleGroups::Scope::AfterSeed::BehavesLikeAnExportableToExcelModel::WhenImportingFromSpreadsheet::AXlsxFile>)>

It turns impossible to use the shell when the level is too deep, and this scope information becomes pointless. How can I hide this scope to something like pry(#hidden_info>)> and still have the methods and variables from the previous scope?

like image 770
intmarinoreturn0 Avatar asked Mar 18 '26 08:03

intmarinoreturn0


1 Answers

The pry prompt can be configured in a variety of ways. The prompt value can take any arbitrary form. (the limit is whatever you can do in Ruby)

You can see the DEFAULT_PROMPT values in the rdocs:

[
 proc { |target_self, nest_level, pry|
   "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
 },

 proc { |target_self, nest_level, pry|
   "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
 }
]

In your case, you would probably want to put the following into ~/.pryrc and then restart any pry sessions:

Pry.config.prompt = [
 proc { |target_self, nest_level, pry|
   "[#{pry.input_array.size}] #{pry.config.prompt_name}#{":#{nest_level}" unless nest_level.zero?}> "
 },

 proc { |target_self, nest_level, pry|
   "[#{pry.input_array.size}] #{pry.config.prompt_name}#{":#{nest_level}" unless nest_level.zero?}* "
 }
]

This removes the Pry.view_clip(target_self) call which will clip the class from the prompt.

There are examples here on Stack Overflow for configuring the pry prompt as well.

like image 147
anothermh Avatar answered Mar 20 '26 21:03

anothermh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!