From: David Masover Date: 2009-09-24T14:29:00+09:00 Subject: Re: How do you limit the line length of the output commands? Where is pqueue library documented? On Wednesday 23 September 2009 09:07:16 pm Mason Kelsey wrote: > I am running my Ruby code on SciTE, a free IDE that came with the download. There you go. If you run Ruby outside of SciTE, does that class exist? > I tried the code: > retrieve pp What does this do? I'm not aware of a 'retrieve' method in Ruby. Maybe you meant something like this: require 'pp' > and it produce the names of all of the methods for the priority queue, one > on each line. Better than just one line but not good enough. What I'd assumed, but can't find decent documentation for, is that pp can customize the output somewhat. > I did the same thing for > pp pp.methods > and got the methods of pp. When you run pp like this: pp foo.methods That expands to this: pp(foo.methods) So what you're really doing is trying to find: pp().methods Does that make any sense? In other words, you're treating pp like an object, which it's not. You're actually calling 'methods' on the return value of the _method_ pp, which returns nil for me. In other words, what you're doing is probably equivalent to looking at nil.methods. > I noticed that many were shared by pq, making > me think that they inherited from a super class that they both must belong > to. Probably true. It's not trivial to find out whether a method is inherited from within Ruby. I've been doing things like this, from the commandline: ri pp That, and otherwise looking at methods. > I tried > pp(pq.methods, out=$>, width=60) Giant, gaping syntax error: Ruby doesn't really have keyword arguments. That's showing what the argument is called, and what its default value is -- in other words, it's showing how you might define it. So, you probably wanted: PP.pp(pq.methods, $> 60) This still won't do what you want, though -- it works well enough for arrays that fit on one line, but as soon as the array spans multiple lines, it shows one per line. And yes, reading the source, you do have to call PP.pp if you want to use those arguments. The normal 'pp' is a wrapper that just calls PP.pp on each of its arguments, which is why you got a '60' at the end. > It is very interesting as it prints out five or six methods per line, > staying under 60 character length. Sounds like exactly what you wanted. So what's the problem? > Still, Ruby needs a simple formatter for its display output class. What "display output class"? And why? > But at least I can stick this in a method and use it in the future. Exactly. Why should this be part of the language, or even the standard library? Ruby is used in all sorts of places. It seems to be quite popular on the web, for example, where output is to a web browser which can clearly word-wrap for you. I can't remember ever wanting this feature. So, if it's useful to you, by all means, put it in a function, or find a library that serves your purpose. Or write one, make a gem, and share it with the world. But what you're suggesting makes no sense. Ruby doesn't have a "display output class". It has IO classes, which may or may not have anything to do with display. It also has bindings to various GUI and network libraries, which might be what it's using for display instead. I would suggest it's not really Ruby's job, nor is it necessarily even the job of the program you're writing. If you're on any sort of Unix, I'd suggest piping the output through the 'fold' command. If you're outputting to anything other than the terminal, there's a good chance that tool will support word-wrapping -- which is why I asked if you were using something like Notepad to view the output. Surely SCiTE should have some option to wrap long lines for you, if not on individual words.