Inspect question/request

Hello,

When Ruby stumbles upon an object with a missing method, it says something
like this:

undefined method `foo’ for #Object:0x28091a0

However, that is not what inspect returns for that object. It would be
really helpful to me if I could tell Ruby to call inspect like it normally
does, rather than just telling me what class it’s in.

In my particular situation, I am using Modules all over the place instead of
classes. (It makes sense in this particular context.) `foo’ might need to
be defined in one of the modules (but I don’t know which one because the
real inspect wasn’t called), or this might be the wrong kind of object,
signifying a bug elsewhere (but I don’t know what kind of object this is,
since the real inspect wasn’t called).

:frowning:

Chris

Hi,

···

In message “inspect question/request” on 03/03/31, “Chris Pine” nemo@hellotree.com writes:

When Ruby stumbles upon an object with a missing method, it says something
like this:

undefined method `foo’ for #Object:0x28091a0

However, that is not what inspect returns for that object. It would be
really helpful to me if I could tell Ruby to call inspect like it normally
does, rather than just telling me what class it’s in.

Yeah, right. It’s been like that from the beginning, but I don’t
remember why I did so. OK, I will change to use “inspect” and see how
it work.

						matz.

Hi,

···

At Mon, 31 Mar 2003 11:15:06 +0900, Yukihiro Matsumoto wrote:

When Ruby stumbles upon an object with a missing method, it says something
like this:

undefined method `foo’ for #Object:0x28091a0

However, that is not what inspect returns for that object. It would be
really helpful to me if I could tell Ruby to call inspect like it normally
does, rather than just telling me what class it’s in.

Yeah, right. It’s been like that from the beginning, but I don’t
remember why I did so. OK, I will change to use “inspect” and see how
it work.

If the object doesn’t have “inspect”, it will cause infinite
recursion. Isn’t this the reason?


Nobu Nakada

Hi,

···

In message “Re: inspect question/request” on 03/03/31, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

If the object doesn’t have “inspect”, it will cause infinite
recursion. Isn’t this the reason?

I don’t think so. There’s Object#inspect defined, so that it would
not happen unless somebody “undef” inspect explicitly.

						matz.

Hi,

···

At Mon, 31 Mar 2003 11:58:38 +0900, Yukihiro Matsumoto wrote:

If the object doesn’t have “inspect”, it will cause infinite
recursion. Isn’t this the reason?

I don’t think so. There’s Object#inspect defined, so that it would
not happen unless somebody “undef” inspect explicitly.

But it were happen, it might be hard to detect, I guess. Or
even it is the desired result when undefines inspect?


Nobu Nakada

Hi,

···

In message “Re: inspect question/request” on 03/03/31, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

I don’t think so. There’s Object#inspect defined, so that it would
not happen unless somebody “undef” inspect explicitly.

But it were happen, it might be hard to detect, I guess. Or
even it is the desired result when undefines inspect?

Who wants to undef “inspect”?

						matz.

Yukihiro Matsumoto wrote:

Hi,

I don’t think so. There’s Object#inspect defined, so that it would
not happen unless somebody “undef” inspect explicitly.

But it were happen, it might be hard to detect, I guess. Or
even it is the desired result when undefines inspect?

Who wants to undef “inspect”?

  					matz.

If something, no matter how stupid, is possible, then someone, somewhere
will do it.

Perhaps in the absence of an inspect method (for whatever reason), a
fall-back to the original behavior is in order?

···

In message “Re: inspect question/request” > on 03/03/31, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

A thread some time ago discussed the creation of absolutely plain
objects with no methods or anything defined. I don’t know if anyone
is still interested in that but it would be a shame if an error failed
to print while they were experimenting.

Gavin

···

On Monday, March 31, 2003, 2:30:09 PM, Yukihiro wrote:

Hi,

In message “Re: inspect question/request” > on 03/03/31, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

I don’t think so. There’s Object#inspect defined, so that it would
not happen unless somebody “undef” inspect explicitly.

But it were happen, it might be hard to detect, I guess. Or
even it is the desired result when undefines inspect?

Who wants to undef “inspect”?

Hi,

···

At Mon, 31 Mar 2003 13:53:03 +0900, Julian Snitow wrote:

Perhaps in the absence of an inspect method (for whatever reason), a
fall-back to the original behavior is in order?

Yes, it will be possible and parhaps reasonable. I just tried
to guess the reason why matz made it like as current.


Nobu Nakada

Hi,

···

In message “Re: inspect question/request” on 03/03/31, Julian Snitow vangczung@yahoo.com writes:

Who wants to undef “inspect”?

If something, no matter how stupid, is possible, then someone, somewhere
will do it.

Perhaps in the absence of an inspect method (for whatever reason), a
fall-back to the original behavior is in order?

I know. I did it once, and asked myself how often it occurs, and how
much it cost to cover it, then removed fall back code. Was I wrong?

						matz.

Hi,

···

In message “Re: inspect question/request” on 03/03/31, Gavin Sinclair gsinclair@soyabean.com.au writes:

Who wants to undef “inspect”?

A thread some time ago discussed the creation of absolutely plain
objects with no methods or anything defined. I don’t know if anyone
is still interested in that but it would be a shame if an error failed
to print while they were experimenting.

Sounds reasonable. You succeeded to persuade me.

						matz.

Yukihiro Matsumoto wrote:

Hi,

Who wants to undef “inspect”?

If something, no matter how stupid, is possible, then someone, somewhere
will do it.

Perhaps in the absence of an inspect method (for whatever reason), a
fall-back to the original behavior is in order?

I know. I did it once, and asked myself how often it occurs, and how
much it cost to cover it, then removed fall back code. Was I wrong?

  					matz.

I doubt that the test would affect the performance of correct code if
it’s performed in the error-handling routine (unless there’s an obscure
implemetation detail that I’m overlooking :-), and it seems to me that
being able to “fail correctly” is important in a language that allows
graceful recovery from exceptions.

If, on the other hand, there were an actual performance hit for
non-buggy code (i.e., code that doesn’t call non-existent methods very
often), then that would be another matter entirely. :slight_smile:

···

In message “Re: inspect question/request” > on 03/03/31, Julian Snitow vangczung@yahoo.com writes: