From 61cbb0f021df1ccfd2765975493d7d2ec04038e6 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 28 Apr 2017 14:21:06 -0500 Subject: [PATCH] Add Ins And Outs Of Pry as a ruby til --- README.md | 3 ++- ruby/ins-and-outs-of-pry.md | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ruby/ins-and-outs-of-pry.md diff --git a/README.md b/README.md index 3b24044..d44c05d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_528 TILs and counting..._ +_529 TILs and counting..._ --- @@ -393,6 +393,7 @@ _528 TILs and counting..._ - [Finding The Source of Ruby Methods](ruby/finding-the-source-of-ruby-methods.md) - [Identify Outdated Gems](ruby/identify-outdated-gems.md) - [If You Detect None](ruby/if-you-detect-none.md) +- [Ins And Outs Of Pry](ruby/ins-and-outs-of-pry.md) - [Invoking Rake Tasks Multiple Times](ruby/invoking-rake-tasks-multiple-times.md) - [Last Raised Exception In The Call Stack](ruby/last-raised-exception-in-the-call-stack.md) - [Limit Split](ruby/limit-split.md) diff --git a/ruby/ins-and-outs-of-pry.md b/ruby/ins-and-outs-of-pry.md new file mode 100644 index 0000000..89b61b2 --- /dev/null +++ b/ruby/ins-and-outs-of-pry.md @@ -0,0 +1,26 @@ +# Ins And Outs Of Pry + +When executing commands during a [Pry](http://pryrepl.org/) session, you'll +see an incrementing number for each prompt as you enter each statement. +These numbers can be used to look up the inputs and outputs of each +statement executed during the session. The statements and their results are +made available in the array-like `_in_` and `_out_` objects. + +```ruby +[1] pry(main)> :one +=> :one +[2] pry(main)> 1 + 1 +=> 2 +[3] pry(main)> ["t", "h", "r", "e", "e"].join +=> "three" +[4] pry(main)> _in_.to_a +=> [nil, ":one\n", "1 + 1\n", "[\"t\", \"h\", \"r\", \"e\", \"e\"].join\n"] +[5] pry(main)> _out_.to_a +=> [nil, :one, 2, "three", [nil, ":one\n", "1 + 1\n", "[\"t\", \"h\", \"r\", \"e\", \"e\"].join\n"]] +[6] pry(main)> _out_[2] +=> 2 +[7] pry(main)> _in_[2] +=> "1 + 1\n" +``` + +[source](https://github.com/pry/pry/wiki/Special-Locals#In_and_out)