From: Patrick Okui Date: 2009-09-24T08:07:06+09:00 Subject: Re: How do you limit the line length of the output commands? Where is pqueue library documented? On 9/24/09 12:59 AM, Mason Kelsey wrote: > First Question: What is an easy way to modify the below puts code to control > line length without truncation? > > require "pqueue" > pq=PQueue.new(proc{|x,y| x[0][0] puts pq.methods.join(', ') # Displays the methods of PQueue Class > > I've a tried puts, print, and p and they never do a word wrap or such. Is > there a secret parameter for controlling the line length before word wrap > occurs in these commands? PP::pp has a width parameter, but in this case I think it'll print one method per line (not say 10 per line) if you did PP::pp pq.methods. If that doesn't satisfy you I'd guess you're stuck with stuffing the methods into the end of a buffer yourself. (sorry this feels more like C than ruby to this ruby newbie but I can't think of a simpler way) 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 > Second question: The pqueue library is not documented in > http://www.ruby-doc.org/stdlib/. Is there a > reason for that? Or is it cleverly hidden in a class that doesn't seem to > have anything to do with priority queues? I'm not sure how you got pqueue but in my case (to test this example) I had to install it as a gem i.e it's not distributed with my ruby (1.8.7). gem query -d -n pqueue gives http://death.rubyforge.org/ as the homepage so that's where I'd start looking. -- patrick