Installing and using 'shim'

I’ve downloaded ‘shim’ from the RAA. It provides a 1.6 system with
several 1.8 capabilities. My main aim was to use StringIO, which,
despite being mentioned a few times here, seems to have no independent
presence on the RAA/web.

Some comments:

  • installation was not straightforward (well, I think I just did
    something wring, but there were no real instructions)
  • documentation is sparse (thin and spread out)
  • I’ve found no instructions on using StringIO!

Don’t get me wrong, I’m very grateful for the package. It seems to be
packaged automatically, which is sensible but unusual. A top-level
document descibing the overall package, where to find things, etc.
would be great. I’m happy to contribute, but I obviously don’t have
the knowledge to get it started.

I may have missed some stuff - all the documentation is in RD and I’m
too lazy to convert it to HTML.

Anyone else using it? Any comments?

Gavin

- I've found no instructions on using StringIO!

StringIO is one of these extensions which don't need documentation, or
more precisely just need to document ::new, #initialize

Once you have created a StringIO object, it must respond exactly like an
IO object. Just the differences must be given (see the file README)

Add documentation for StringIO is just like duplicate the documentation
for IO.

Guy Decoux

  • I’ve found no instructions on using StringIO!

StringIO is one of these extensions which don’t need documentation, or
more precisely just need to document ::new, #initialize

Once you have created a StringIO object, it must respond exactly like an
IO object. Just the differences must be given (see the file README)

The README omits the string and string= methods that are defined in
the C source.

I expect more than just IO-like behaviour from a class called
StringIO.

Add documentation for StringIO is just like duplicate the documentation
for IO.

I don’t mean full documentation, but some examples of use would be
nice. Unit tests are good for that, and that’s what I used.
Unfortunately, they don’t test the string and string= methods!

Maybe I’m not supposed to be using these methods. I don’t know how
else to achieve my goal. That’s why some demonstrations would be
nice. (Just checked Wiki, nothing there.)

I’ll detail my problem in a different thread, unless I can solve it
soon.

Gavin

···

On Thursday, January 16, 2003, 2:53:31 AM, ts wrote:

I seem to remember something like this in Ruby, but I can’t find it now. In
Python there is the concept of a doc string; a String of text just inside a
method of class definition. You can get this string at runtime by asking
for an attribute called DOC. Is there anything equivalent in Ruby?

···


I expect more than just IO-like behaviour from a class called
StringIO.

Then never use my extensions, because they are initially based on this
(they just *try* to emulate a ruby standard class) :-))

I don't mean full documentation, but some examples of use would be
nice. Unit tests are good for that, and that's what I used.
Unfortunately, they don't test the string and string= methods!

I'm sure that the author of the extension will be happy with a patch.

Guy Decoux

No. The closest thing (which isn’t even close, because it’s not
runtime-accessible, but at least it’s “literate programming”) is RDoc,
with which you can document each method in the source code, and
extract (painlessly) that documentation into HTML and other targets.

Gavin

···

On Thursday, January 16, 2003, 4:54:11 AM, Joey wrote:

I seem to remember something like this in Ruby, but I can’t find it now. In
Python there is the concept of a doc string; a String of text just inside a
method of class definition. You can get this string at runtime by asking
for an attribute called DOC. Is there anything equivalent in Ruby?

Or, try this:

class Module
def doc(x = nil)
if not x.nil?
@@doc = x
end
@@doc
end
end

class Foo
doc “some docs for class Foo”

rest of Foo stuff here

end

f = Foo.new
f.class.doc # => “some docs for class Foo”

Foo.doc # => “some docs for class Foo”

I think this was posted to the ML a few months ago.

– Dossy

···

On 2003.01.16, Gavin Sinclair gsinclair@soyabean.com.au wrote:

On Thursday, January 16, 2003, 4:54:11 AM, Joey wrote:

I seem to remember something like this in Ruby, but I can’t find it now. In
Python there is the concept of a doc string; a String of text just inside a
method of class definition. You can get this string at runtime by asking
for an attribute called DOC. Is there anything equivalent in Ruby?

No. The closest thing (which isn’t even close, because it’s not
runtime-accessible, but at least it’s “literate programming”) is RDoc,
with which you can document each method in the source code, and
extract (painlessly) that documentation into HTML and other targets.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Dossy wrote:

Or, try this:

class Module
def doc(x = nil)
if not x.nil?
@@doc = x
end
@@doc
end
end

class Foo
doc “some docs for class Foo”

rest of Foo stuff here

end

f = Foo.new
f.class.doc # => “some docs for class Foo”

Foo.doc # => “some docs for class Foo”

I think this was posted to the ML a few months ago.

– Dossy

I was just thinking about how you could use doc inside a method call
and dynamically add doc information to the symbol representing the
method from which you call it. This brings me to a question: How do
you find out where a method is called from? I used to do this in Java
through some nasty stack trace hacks (throw an exception and
capture/parse the stack trace string). I seem to remember when I was
first learning Ruby a couple of years ago that there is a better way to
do this in Ruby, but I can’t seem to specifically remember what it was.

Anyone know?

This way, you could potentially extend this doc idea to work like this:

class Symbol
attr_accessor :doc
end

def some_method
doc “This is what some_method does…” #=> doc string would now
be accessible via :some_method.doc
end

class Test
doc “Documentation for class” #=> Now, :Test.doc returns the doc
string
end

…and so on.

I’m not sure how useful any of this is (never used the doc string
concept, personally), but now I want to know how to do it. Hopefully
I’m just forgetting something obvious.

Chad

Do you mean caller?

[mike@ratdog mike]$ ri caller
--------------------------------------------------------- Kernel::caller
caller( [anInteger] ) → anArray

···

In article 3E25ADE1.5050700@chadfowler.com, Chad Fowler wrote:

[…] This brings me to a question: How do
you find out where a method is called from? I used to do this in Java
through some nasty stack trace hacks (throw an exception and
capture/parse the stack trace string). I seem to remember when I was
first learning Ruby a couple of years ago that there is a better way to
do this in Ruby, but I can’t seem to specifically remember what it was.

Anyone know?


 Returns the current execution stack---an array containing strings
 in the form ``file:line'' or ``file:line: in `method'''. The
 optional anInteger parameter determines the number of initial stack
 entries to omit from the result.
    def a(skip)
      caller(skip)
    end
    def b(skip)
      a(skip)
    end
    def c(skip)
      b(skip)
    end
    c(0)   #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10"]
    c(1)   #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11"]
    c(2)   #=> ["prog:8:in `c'", "prog:12"]
    c(3)   #=> ["prog:13"]

Hope this helps,

Mike


mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA

How do you find out where a method is called from?

There’s the “caller” method that returns a stack list.

I used to do this in Java
through some nasty stack trace hacks (throw an exception and
capture/parse the stack trace string).

So have I; it’s pretty nasty.

I’m not sure how useful any of this is (never used the doc string
concept, personally), but now I want to know how to do it. Hopefully
I’m just forgetting something obvious.

I generally have used DOC when I’m in an interactive Python session and
I can’t remember what a class/method does.

Joey

···

On Thu, 16 Jan 2003 03:52:44 +0900, Chad Fowler chadfowler@chadfowler.com wrote: