Caller lies, or Method#id is wrong, or both

So, caller lies. I suspect this is true no matter what. It may also be
the case that Method#id is wrong as well… it might not. There isn’t a
formal spec on this language, so I can only guess… Here’s my problem.
It’s related to the RubyInline issue that came up a few days ago. Here
is a brief (I hope) description of the problem, followed by some code
to assert the case:

A user aliases a method that calls inline. Inline does it’s thing and
replaces (via alias) the old method with the new optimized method. But
the user is calling the method through his alias. That is where caller
lies. Caller says that the method one level up from inline is the
original method, not the alias. This would be fine except that
method(:oldm).id != method(:newm).id. So not only can I not optimize
and replace the alias based on the name via caller, but I also can’t
iterate over the methods to see which ones are aliases of the original
and replace them all.

#!/usr/local/bin/ruby -w

class CallerBug

def whoami?
return caller[0]
end

def oldcaller
return self.whoami?
end

alias :newcaller :oldcaller

end

bug = CallerBug.new

p bug.method(:oldcaller).id == bug.method(:newcaller).id
p bug.oldcaller != bug.newcaller

both tests at the end return false.

So, here are my questions:

  1. What can I do to solve my problem with RubyInline, with current
    versions of ruby??
  2. Are either of these a bug?
  3. Does method(:name).id return the id of the method instance, or the
    name?
  4. If #3=instance, what is the rationale for rb_alias to create a new
    method entirely via NEW_METHOD(NEW_FBODY(…))?

3) Does method(:name).id return the id of the method instance, or the
name?

#method create a new object.

#id just return the ID of this object

4) If #3=instance, what is the rationale for rb_alias to create a new
method entirely via NEW_METHOD(NEW_FBODY(...))?

See the comment in the source

Guy Decoux

  1. Does method(:name).id return the id of the method instance, or
    the
    name?

#method create a new object.

ARGH! You are right. It makes a copy so you can use it as a closure.
‘ri’ misled me in it’s first sentence Then how does one simply look up
a method for a class w/o creating a copy of it? I need to find and
alias all methods that are the same as the one that I’m interested in.

I have a feeling that the things I’ve been touching upon lately hint
that ruby’s reflection model is a bit wack and could be made cleaner,
but at what cost? I’d like for reflection methods to return the real
thing. If I want a closure, I can make a proc out of it on my own. We
could even add a to_proc or to_closure method to make that clearer.
method(:blah).to_closure seems the ruby way to me.

#id just return the ID of this object

  1. If #3=instance, what is the rationale for rb_alias to create a
    new
    method entirely via NEW_METHOD(NEW_FBODY(…))?

See the comment in the source

What comment? The only comment I see for rb_alias is /* was alias */,
which doesn’t help me a bit. I’m looking at 1.7-2002-07-15. Should I be
looking at 1.6? This behavior exists in both versions.

For a nearly 10k line file, I’d kinda hope for more than 173 comments.

···

On Sunday, September 22, 2002, at 01:58 AM, ts wrote:

What comment? The only comment I see for rb_alias is /* was alias */,

It's suffisant

For a nearly 10k line file, I'd kinda hope for more than 173 comments.

You are right : there are too many comments in the source

Guy Decoux