Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
How do you limit the line length of the output commands? Where ispqueue library documented?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mason Kelsey, post: 4649340"] [Note: parts of this message were removed to make it a legal post.] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
How do you limit the line length of the output commands? Where ispqueue library documented?
Top