On Thu, May 16, 2013 at 7:32 PM, Dermot C. <lists / ruby-forum.com> wrote:

> Guys, FYI caller doesn't give meaningful data about method when the
> method is called from a bare file, e.g. a Cucumber Step definition.
>

What exactly distinguishes a "bare file" from ordinary ruby code?


> Instead of giving
>
> common_steps.rb:42:in `some_method_or_other' ...
>
> it gives
>
> common_steps.rb:42:in `block in <top (required)>' ...
>
> For these situations you're better off using __method__ and
> self.name.to_s if you also need the class in which the method is
> contained.


You could as well just look at the next item in the list and use that:

$ ruby -e 'def f;p caller(1);end;f;1.times {f}'
["-e:1:in `<main>'"]
["-e:1:in `block in <main>'", "-e:1:in `times'", "-e:1:in `<main>'"]

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/