I've got a recursive object (Cucumber::Rails::World.scenario) which I'd like to inspect (in order to find the tags belonging to the current scenario). scenario.inspect never finishes, and pp scenario prints so fast that even with a quick series of Ctrl-c it fills about three thousand lines. How can I limit the output?
Use pretty_inspect to get it as a string, then get only the first n characters:
pp_output = scenario.pretty_inspect; nil
puts pp_output[0..n]; nil
Note the trailing nils cause IRb to display the return value nil rather than the entire object, which cleans up output substantially.
For even more flexibility, save it to a file:
File.open "pp-output.txt", "w" do |f|
f.puts scenario.pretty_inspect
end
Then view in the pager of your choice:
$ less pp-output.txt
Insert gets at certain points (in between small chunks of pp). Then, you can go through them slowly by inputting enter after each chunk.