# Using the p command to print files

**URL:** <https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515>\
**Category:** Ruby\
**Created:** [January 2, 2006, 4:43am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515 "2006-01-02T04:43:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 4:43am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/1 "2006-01-02T04:43:14Z")

</div>

If any one has a copy of “why’s poignant guide to ruby”, turn to page  
45. I can see immediately that  
i)`ruby p Dir ['*']` works and lists all files within a specified  
directory. However  
ii)`ruby p File::methods` produces the error…“ruby: No such file or  
directory – p (LoadError)”  
Is ii) just a way to show the generic syntax of the command?

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 6:28am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/2 "2006-01-02T06:28:28Z")

</div>

[John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), 2006-01-02 04.42 CET]

> If any one has a copy of “why’s poignant guide to ruby”, turn to page 45. I can see immediately that  
> i)`ruby p Dir ['*']` works and lists all files within a specified directory. However  
> ii)`ruby p File::methods` produces the error…“ruby: No such file or directory – p (LoadError)”  
> Is ii) just a way to show the generic syntax of the command?

I downloaded the PDF file and didn’t find what you wrote on page 45,  
only  
something like it on page 35. Next time please try to find the relevant  
html  
page (it is a little upwards from  
[http://poignantguide.net/ruby/chapter-4.html#section4](http://poignantguide.net/ruby/chapter-4.html#section4)).

The examples given are:

i) p Dir[‘idea-\*.txt’]

ii) p File::methods

(there are no “ruby” or backticks). You should try them on an irb shell,  
or  
writing them on a file and then running it with “ruby file”, or passing  
them  
as a parameter to ruby, after the parameter “-e”, so:

ruby -e “p Dir[‘idea-\*.txt’]”

ruby -e “p File::methods”

It’s best to do that only if you understand how your command shell  
interprets quotes.

Good luck.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 6:34am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/3 "2006-01-02T06:34:40Z")

</div>

> ii) just a way to show the generic syntax of the command?

If you’ve done a full Ruby install, you should have the ri command at  
your disposal:

Example usage:  
ri Object  
ri Object::new  
ri Kernel#p

-Ben

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 8:29am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/4 "2006-01-02T08:29:41Z")

</div>

Benjamin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ri Object::new  
> ~/Desktop/ruby-1.8.4%\> ri Object::new  
> ------------------------------------------------------------ Object::new  
> Object::new()

* * *

```
 Not documented

```

~/Desktop/ruby-1.8.4%\> ri Kernel#p  
zsh: no matches found: Kernel#p

just for fun )))

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 8:44am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/5 "2006-01-02T08:44:47Z")

</div>

On Jan 1, 2006, at 11:27 PM, Une bévue wrote:

> ~/Desktop/ruby-1.8.4%\> ri Kernel#p  
> zsh: no matches found: Kernel#p
> 
> ## just for fun )))
> 
> une bévue

(~/):~\>$: ri “Kernel#p”

## --------------------------------------------------------------- Kernel#p p(obj, …) =\> nil

```
  For each object, directly writes obj.inspect followed by the
  current output record separator to the program's standard output.
  p bypasses the Ruby I/O libraries.

     S = Struct.new(:name, :state)
     s = S['dave', 'TX']
     p s

  produces:

     #<S name="dave", state="TX">

```

you need to quote it because of the # char

Cheers-  
Ezra

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 2, 2006, 11:15am UTC](https://www.ruby-forum.com/t/using-the-p-command-to-print-files/51515/6 "2006-01-02T11:15:20Z")

</div>

Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> you need to quote it because of the # char

fine, thanks, i got it 😉
