Mario, there once was a library called binding_of_caller, which I
think could do what you wanted, but I think it doesn't work anymore
with recent Ruby versions.
There is no such thing as the "caller of a class": a class can be used
by many clients and only methods are actually "called". "caller" is
actually already defined. See whether this helps:
This is profoundly unhelpful, I know: but perhaps you should consider
redesigning your method so that it doesn't care where it was called
from? That would be more in line with Object Oriented design.
You might find that it belongs on another class, for example the
parent class of all the classes that you are currently considering
calling it from.
Or you could leave it where it is and pass some sort of mode string, instead:
def doit(mode)
case mode
when :full then ...
when :quick then ...
end
end
···
On 8/1/08, Robert Klemme <shortcutter@googlemail.com> wrote:
2008/8/1 Mario Ruiz <mario@betware.com>:
There is no such thing as the "caller of a class": a class can be used
by many clients and only methods are actually "called". "caller" is
actually already defined. See whether this helps:
--
use.inject do |as, often| as.you_can - without end
--
Me, I imagine places that I have never seen / The colored lights in
fountains, blue and green / And I imagine places that I will never go
/ Behind these clouds that hang here dark and low
But it's there when I'm holding you / There when I'm sleeping too /
There when there's nothing left of me / Hanging out behind the
burned-out factories / Out of reach but leading me / Into the
beautiful sea
Good point! After rereading the original posting I would suggest the
same. Just pass on the calling instance or the bit of data that the
method needs. That's what method arguments are for.
Kind regards
robert
···
2008/8/1 <shadowfirebird@gmail.com>:
This is profoundly unhelpful, I know: but perhaps you should consider
redesigning your method so that it doesn't care where it was called
from? That would be more in line with Object Oriented design.
--
use.inject do |as, often| as.you_can - without end
On Fri, Aug 1, 2008 at 10:25 PM, Mario Ruiz <mario@betware.com> wrote:
I know that way.... but I would like to know if it is possible to do it
without passing the argument to the method.
------------------------------------------------------------------------
Returns the current execution stack---an array containing strings
in the form ``file:line'' or ``file:line: in `method'''. The
optional start parameter determines the number of initial stack
entries to omit from the result.