On Wednesday 23 September 2009 09:07:16 pm Mason K. 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:
What does this do? I’m not aware of a ‘retrieve’ method in Ruby. Maybe
meant something like this:
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
customize the output somewhat.
I did the same thing for
and got the methods of pp.
When you run pp like this:
That expands to this:
So what you’re really doing is trying to find:
Does that make any sense?
In other words, you’re treating pp like an object, which it’s not.
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
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
Probably true. It’s not trivial to find out whether a method is
within Ruby. I’ve been doing things like this, from the commandline:
That, and otherwise looking at methods.
pp(pq.methods, out=$>, width=60)
Giant, gaping syntax error: Ruby doesn’t really have keyword arguments.
showing what the argument is called, and what its default value is – in
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
that fit on one line, but as soon as the array spans multiple lines, it
one per line.
And yes, reading the source, you do have to call PP.pp if you want to
those arguments. The normal ‘pp’ is a wrapper that just calls PP.pp on
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.
Why should this be part of the language, or even the standard library?
used in all sorts of places. It seems to be quite popular on the web,
example, where output is to a web browser which can clearly word-wrap
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
But what you’re suggesting makes no sense. Ruby doesn’t have a “display
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,
might be what it’s using for display instead.
I would suggest it’s not really Ruby’s job, nor is it necessarily even
of the program you’re writing. If you’re on any sort of Unix, I’d
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
were using something like Notepad to view the output. Surely SCiTE
some option to wrap long lines for you, if not on individual words.