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

Ask a Question related to Ruby, Design and Development.

  1. #1

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

    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?
    Ed Baker Guest

  2. Similar Questions and Discussions

    1. Using examples
      I am new to flex and have purchased a few components with examples. What are the step by step instructions for using the projects within Flex....
    2. Examples for Feb CTP
      Hi people! I have visit the page ...
    3. ASP Flex examples
      I'm not huge on ASP VBScript, but I do have a requirement to get an example together of the Shopping Cart example working with MXML and Flex Builder...
    4. learning examples
      I am following an online study to learn Perl. I wrote my first 2 programs and run them but unable to find what's wrong with them. the first is as...
    5. HTMLRendering examples?
      In article <r.ortega-796F48.10383521052003@news.speakeasy.net>, Raoul Ortega <r.ortega@mouse-potato.com> wrote: Of course, if you can assume a...
  3. #2

    Default Re: Tanaka Akira's PrettyPrint usage? Are there any examples?

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

    [url]http://whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh[/url]

    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?

    why the lucky stiff Guest

  4. #3

    Default Re: Tanaka Akira's PrettyPrint usage? Are there any examples?

    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):
    >
    > [url]http://whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh[/url]
    >
    > 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?
    Ed Baker Guest

  5. #4

    Default Re: Tanaka Akira's PrettyPrint usage? Are there any examples?

    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):
    >
    > [url]http://whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh[/url]
    >
    > 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?
    Ed Baker Guest

  6. #5

    Default Re: Tanaka Akira's PrettyPrint usage? Are there any examples?

    On 4 Sep 2003 04:10:32 -0700
    [email]ejb@theworld.com[/email] (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
    Jason Creighton Guest

  7. #6

    Default Code beautifier (was Re: Tanaka Akira's PrettyPrint usage? Are there any examples?)

    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

    why the lucky stiff Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139