Encontrar el método de llamada en Ruby [duplicado]
Frecuentes
Visto 597 veces
1
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?
1 Respuestas
0
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 ruby or haz tu propia pregunta.
Not a built-in method, but there's a similar question here: stackoverflow.com/questions/5100299/… - Pete Schlette
Yeah, I guess it's not so bad to use it like that. Thanks. - janko-m