1.8-intense class tree

I was trying to come up with some example code for ‘prettyprint’ and I
remembered Hal’s class diagram. This is somewhat ugly in the details,
but it does show some 1.7/1.8 features: prettyprint, Hashes with blocks
for unknown values, and Enumerable#sort_by.

Cheers

Dave

require ‘prettyprint’

@children = Hash.new { |h,k| h[k] = Array.new }
ObjectSpace.each_object(Class) { |cls| @children[cls.superclass] << cls}

def print_children_of(pp, cls)
pp.group do
pp.text(cls.name)
pp.group do
kids = @children[cls].sort_by {|k| k.name}
unless kids.empty?
pp.text ’ ['
pp.nest(3) do
pp.breakable
kids.each do |k|
next if k == Exception || k.name =~ /^Pretty/
unless pp.first?
pp.text ','
pp.breakable
end
print_children_of(pp, k)
end
end
pp.breakable
pp.text ']'
end
end
end
end

pp = PrettyPrint.new($stdout, 40)
print_children_of(pp, Object)
pp.flush
puts

Neat. Runs fine on 1.7.3.

But if you’re referring to the code that
outputs a class diagram in ASCII form,
that was someone else’s work.

Hmm, never heard of prettyprint. Is it
documented anywhere in English? (Yes, I
know it’s doumented in Ruby… :))

Hal

···

----- Original Message -----
From: “Dave Thomas” dave@pragprog.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, May 14, 2003 10:48 PM
Subject: 1.8-intense class tree

I was trying to come up with some example code for ‘prettyprint’ and I
remembered Hal’s class diagram. This is somewhat ugly in the details,
but it does show some 1.7/1.8 features: prettyprint, Hashes with blocks
for unknown values, and Enumerable#sort_by.

Hal E. Fulton wrote:

Hmm, never heard of prettyprint. Is it
documented anywhere in English? (Yes, I
know it’s doumented in Ruby… :))

I’m working on it… :slight_smile:

In article 03a101c31a9a$d1ea8800$0300a8c0@austin.rr.com,
“Hal E. Fulton” hal9000@hypermetrics.com writes:

Hmm, never heard of prettyprint. Is it
documented anywhere in English? (Yes, I
know it’s doumented in Ruby… :))

prettyprint.rb includes documentation in English.

···


Tanaka Akira

If you are referring to the idea of prettyprint then it goes back a bit
as I recall references to the term in:

Henry F. Ledgard and Louis J. Chmura
FORTRAN WITH STYLE Programming Proverbs
New Jersey: Hayden Books, 1978.

I am looking for my copy of the book to verify it. I need to get to
work at the moment and will get back to you tonight about it…

(oh, I guess I de-lurked)

ciao,
furlan

···

— “Hal E. Fulton” hal9000@hypermetrics.com wrote:

Hmm, never heard of prettyprint. Is it
documented anywhere in English? (Yes, I
know it’s doumented in Ruby… :))

=====
http://thispaceavailable.uxb.net/

icq: 34671531

“People think Microsoft is the answer. Microsoft is just the question, “No” is the answer.”


Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

:slight_smile: De-lurk more often. I enjoy that kind of tidbit,
but it wasn’t what I was talking about.

I was asking about Ruby’s prettyprint. But
Tanaka Akira kindly pointed out what should
have been obvious to me – there’s some
documentation inside prettyprint.rb itself.

Cheers,
Hal

···

----- Original Message -----
From: “furlan primus” magicus23@yahoo.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, May 15, 2003 7:01 AM
Subject: Re: prettyprint

If you are referring to the idea of prettyprint then it goes back a bit
as I recall references to the term in:

Henry F. Ledgard and Louis J. Chmura
FORTRAN WITH STYLE Programming Proverbs
New Jersey: Hayden Books, 1978.

I am looking for my copy of the book to verify it. I need to get to
work at the moment and will get back to you tonight about it…

(oh, I guess I de-lurked)