From: Robert Klemme Date: 2013-05-28T17:24:45+09:00 Subject: Re: using the current method name within current method --bcaec53f907b5730ed04ddc2ffbe Content-Type: text/plain; charset=ISO-8859-1 On Thu, May 16, 2013 at 7:32 PM, Dermot C. 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 ' ... > > 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 `
'"] ["-e:1:in `block in
'", "-e:1:in `times'", "-e:1:in `
'"] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --bcaec53f907b5730ed04ddc2ffbe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Thu, May 16, 2013 at 7:32 PM, Dermot C. <lists@ruby-forum.co= m> wrote:
Guys= , FYI caller doesn't give meaningful data about method when the<= br>
method is called from a bare file, e.g. a Cucumber Step definition.

What exactly distinguishes a "bare = file" from ordinary ruby code?
=A0
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 loo= k 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| a= s.you_can - without end
h= ttp://blog.rubybestpractices.com/
--bcaec53f907b5730ed04ddc2ffbe--