Pry – Part 3

So, assuming you’ve been through Part 1 and Part 2, you should have the Hello World gem installed.

We can cd directly into the gem’s source code and look at it directly:

gem-cd hello_world

We can run commands directly by prefixing them with a period.
E.g. look at the file structure layout using tree:

[32] pry(HelloWorld):1> .tree
├── Manifest
├── README.rdoc
├── Rakefile
├── hello_world.gemspec
└── lib
    └── hello_world.rb

1 directory, 5 files
[33] pry(HelloWorld):1> .cd lib/
[34] pry(HelloWorld):1> .cat hello_world.rb
module HelloWorld
  def self.say_hello
    puts 'hello world'
end[35] pry(HelloWorld):1> 

Note that you may need to install tree on MacOSX. E.g.

brew install tree

You can cdd into other objects, e.g.

[35] pry(HelloWorld):1> cd 12 12
[36] pry(12):2> cd String
[37] pry(String):3> 

The prompt updates to show you what object you’re in.



shows you the current nesting status, e.g.

[37] pry(String):3> nesting
Nesting status:
0. main (Pry top level)
1. HelloWorld
2. 12
3. String
[38] pry(String):3> 

Pop out using:

cd ..

or jump to an index:

[38] pry(String):3> jump-to 0
[39] pry(main)>

Input buffers:
Clear out:

[39] pry(main)> def helo(name)
[39] pry(main)*   show-input
1: def helo(name)
[39] pry(main)*   !
Input buffer cleared!
[40] pry(main)>

Say you want to amend a line:

[40] pry(main)> def hello(name)
[40] pry(main)*   "Hello, #{name}
[40] pry(main)* show-input
1: def hello(name)
2:   "Hello, #{name}
[40] pry(main)* amend-line 2 "Hello, #{name}"
1: def hello(name)
2:   "Hello, #{name}"
[40] pry(main)* end  
=> nil
[41] pry(main)> hello "Me"
=> "Hello, Me"
[42] pry(main)> 

Leave a Reply

Your email address will not be published. Required fields are marked *