From: Mason Kelsey Date: 2009-09-24T11:07:16+09:00 Subject: Re: How do you limit the line length of the output commands? Where is pqueue library documented? --00c09f90580d40d9d50474494a11 Content-Type: text/plain; charset=ISO-8859-1 No. I haven't gotten around to learning GEMs yet or downloaded any special libraries. I'm just now becoming aware of the classes that come with1.8, the version I down loaded two months ago. Have not imported any Gems that I am aware of. Not ready for Ruby 1.9 yet. I am running my Ruby code on SciTE, a free IDE that came with the download. But that shouldn't be an issue here as what I want is a code way of controlling the format of my display. I just have to have the code in a particular subdirectory in order for the retrieve to work. I tried the code: retrieve pp pp pq.methods 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. I did the same thing for pp pp.methods and got the methods of pp. I noticed that many were shared by pq, making me think that they inherited from a super class that they both must belong to. I tried pp(pq.methods, out=$>, width=60) as was suggested in the Ruby standard documentation for pretty print. But that just gives me errors, prints out one method per line and the number 60 at the end. I'm not going something right. The code that Patrick suggested works best: buffer = '' pq.methods.each do |m| if buffer.split("\n")[-1].to_s.length + m.length < 60 buffer << ((buffer.length > 0)? ", #{m}": "#{m}") else buffer << "\n#{m}" end end puts buffer It is very interesting as it prints out five or six methods per line, staying under 60 character length. So it gives a much more readable format. Still, Ruby needs a simple formatter for its display output class. But at least I can stick this in a method and use it in the future. Much thanks to everyone for all the useful knowledge, and special thanks to Patrick for the extra mile. Slowly but surely I am learning. No Sam On Wed, Sep 23, 2009 at 7:25 PM, David Masover wrote: > On Wednesday 23 September 2009 04:59:23 pm Mason Kelsey wrote: > > In the puts code > > example below, I want to break between every 10 methods or just go to a > new > > line after every 60 characters that get displayed so they don't run off > the > > screen. > > It sounds like you're viewing your output in something wacky, like Notepad. > Terminals usually wrap things, and so do good text editors -- they'll just > wrap by character, not by word or method. > > I don't know that there's an "easy way" as in "built into the language", > but > there's probably a library to at least wrap on word. After all, it's not > really a property of the IO itself, it's more string manipulation. > > > Is > > there a secret parameter for controlling the line length before word wrap > > occurs in these commands? > > Word wrap does not occur in these commands. If you're seeing word-wrapping > at > all, again, that's likely a text editor or a terminal doing it for you. > > If it's a terminal, I'm really not sure what you're complaining about -- > just > resize the terminal window. > > > Second question: The pqueue library is not documented in > > http://www.ruby-doc.org/stdlib/ . > > Yeah, I have no idea where you got it from. I can't find it in my standard > library for 1.8 or 1.9, or in > > Are you sure you didn't install a gem or something? > > --00c09f90580d40d9d50474494a11--