Encontrar el método de llamada en Ruby [duplicado]

Posible duplicado:
¿Cómo obtener el nombre del método de llamada?

Tengo un metodo #foo. That method can be called from many places (scopes). I need #foo to find out where it was called from. But not the stack trace (like what #caller returns), I want the pure name of the method (like what #__callee__ returns). Does a method for this exist in Ruby?

preguntado el 25 de agosto de 12 a las 22:08

Not a built-in method, but there's a similar question here: stackoverflow.com/questions/5100299/… -

Yeah, I guess it's not so bad to use it like that. Thanks. -

1 Respuestas

puedes usar __method__. Place that in any method body and it should provide the name of the method. And you can always fetch the context by using .class or .class.ancestors.

Respondido 25 ago 12, 22:08

Hmm, parece que __method__ devuelve lo mismo que __callee__ (the name of the current scope). I want the previous scope. So, if #bar , que son #foo, I want a method that I can call from #foo que volvería "bar" - Janko-m

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.