[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Tanaka Akira's PrettyPrint usage? Are there any examples?

ejb

9/4/2003 11:11:00 AM

I'm interested in using the prettyprint module available from RAA.

But, as a relatively new Rubyist, I can't seem to make sense of the included RDOCS.

Has anyone got some simple examples they could share?
5 Answers

why the lucky stiff

9/4/2003 5:09:00 PM

0

I have a brief explanation on WS&NiR (towards the bottom of the page):

http://whytheluckystiff.net/articles/2003/08/04/ruby...

Anything in particular you want to know?

_why

On Thursday 04 September 2003 05:25 am, Ed Baker wrote:
> I''m interested in using the prettyprint module available from RAA.
>
> But, as a relatively new Rubyist, I can''t seem to make sense of the
> included RDOCS.
>
> Has anyone got some simple examples they could share?


ejb

9/4/2003 9:20:00 PM

0

Without sounding incredibly stupid, I want to know how to feed it ruby code and
get back formatted output.

I sort of expected a unix like sytax. i.e. a command line like:
ruby pp.rb myfile.rb > mynewfile.rb



why the lucky stiff <ruby-talk@whytheluckystiff.net> wrote in message news:<200309041108.51867.ruby-talk@whytheluckystiff.net>...
> I have a brief explanation on WS&NiR (towards the bottom of the page):
>
> http://whytheluckystiff.net/articles/2003/08/04/ruby...
>
> Anything in particular you want to know?
>
> _why
>
> On Thursday 04 September 2003 05:25 am, Ed Baker wrote:
> > I''m interested in using the prettyprint module available from RAA.
> >
> > But, as a relatively new Rubyist, I can''t seem to make sense of the
> > included RDOCS.
> >
> > Has anyone got some simple examples they could share?

ejb

9/4/2003 9:40:00 PM

0

Also, did I make a mistake in downloading the pp application from RAA?
Since it''s supposed to be a builtin to v1.8. Should I have left well enough
alone?

It''s like what carburetor means in French: "If it works, don''t touch it"

why the lucky stiff <ruby-talk@whytheluckystiff.net> wrote in message news:<200309041108.51867.ruby-talk@whytheluckystiff.net>...
> I have a brief explanation on WS&NiR (towards the bottom of the page):
>
> http://whytheluckystiff.net/articles/2003/08/04/ruby...
>
> Anything in particular you want to know?
>
> _why
>
> On Thursday 04 September 2003 05:25 am, Ed Baker wrote:
> > I''m interested in using the prettyprint module available from RAA.
> >
> > But, as a relatively new Rubyist, I can''t seem to make sense of the
> > included RDOCS.
> >
> > Has anyone got some simple examples they could share?

Jason Creighton

9/4/2003 10:13:00 PM

0

On 4 Sep 2003 04:10:32 -0700
ejb@theworld.com (Ed Baker) wrote:

> I''m interested in using the prettyprint module available from RAA.
>
> But, as a relatively new Rubyist, I can''t seem to make sense of the
> included RDOCS.
>
> Has anyone got some simple examples they could share?

prettyprint is now included in Ruby, at least as of 1.8. Just from
reading the commands in prettyprint.rb, it appears prettyprint is a
module for building, well, pretty printers.

I can''t share any examples for prettyprint, but I can share some for
''pp'', a library which builds upon prettyprint to provide nice output for
Ruby objects. For example:

>> require ''pp''
=> true
>> ary = Array.new(5) { |i| Array.new(5) { |j| i*j } }
=> [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8], [0, 3, 6, 9, 12], [0, 4, 8, 12, 16]]
>> pp ary
[[0, 0, 0, 0, 0],
[0, 1, 2, 3, 4],
[0, 2, 4, 6, 8],
[0, 3, 6, 9, 12],
[0, 4, 8, 12, 16]]
=> nil
>> pp ENV.select { |k,v| k.length == 3 }
[["PWD", "/usr/lib/ruby/1.8"],
["PS1", "\\w\\$ "],
["PS2", "> "],
["XWM", "ion"]]
=> nil

....and so on. YAML can help pretty-print as well:

>> h = {}; 5.times { |i| h[i] = i**4 }; puts h.to_yaml
---
0: 0
1: 1
2: 16
3: 81
4: 256
=> nil

YAML defines a ''y'' method that''s shorthand for puts obj.to_yaml, ie:

>> h = { "goober" => "lala", 123 => 456, 3.1415 => "PI" }
=> {"goober"=>"lala", 3.1415=>"PI", 123=>456}
>> y h
---
goober: lala
3.1415: PI
123: 456
=> nil

Fun stuff.

Jason Creighton

why the lucky stiff

9/4/2003 11:10:00 PM

0

Ed Baker (ejb@theworld.com) wrote:
>
> I sort of expected a unix like sytax. i.e. a command line like:
> ruby pp.rb myfile.rb > mynewfile.rb
>

If you run pp.rb from the commandline, the library will perform some
basic tests to ensure it is working. Oh, wait a sec. I see what you''re
thinking. You''re looking for something like lint, for beautifying Ruby
code.

PP is for displaying data structures in Ruby, so it won''t do the trick.
Not sure what will.

_why