method-names

Hello,

How do I get the name of the method I'm in (perhaps with line-number) ?
(like the error-stack when failing)

thank you

Opti

<https://ruby-doc.org/core-2.7.0/Kernel.html&gt;

*[1] pry(main)> def mymethod[1] pry(main)* [ __method__,
self.method(__method__).source_location ][1] pry(main)* end=> :mymethod[2]
pry(main)> mymethod=> [:mymethod, ["(pry)", 5]][3] pry(main)>*

-gf-

ยทยทยท

On Sat, Aug 28, 2021 at 7:24 PM Die Optimisten <inform@die-optimisten.net> wrote:

     Hello,

How do I get the name of the method I'm in (perhaps with line-number) ?
(like the error-stack when failing)

thank you

Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hello,

is it possible to do this it only once (metaprogramming), so that it is
done for all (my) methods starting AND ending ?

- Do I have to build the method-call stack by myself, or can I somehow
use the avalilable call-stack?

thank you

Opti

ยทยทยท

--

-gf-

is it possible to do this

What is "this"?

ยทยทยท

On Sun, Aug 29, 2021 at 5:25 PM Die Optimisten <inform@die-optimisten.net> wrote:

It sounds like your intention is to trace and log program execution ? ...
You may find this useful:

-gf-

ยทยทยท

On Sun, Aug 29, 2021 at 11:25 AM Die Optimisten <inform@die-optimisten.net> wrote:

Hello,

is it possible to do this it only once (metaprogramming), so that it is
done for all (my) methods starting AND ending ?

- Do I have to build the method-call stack by myself, or can I somehow
use the avalilable call-stack?

thank you

Opti

--

-gf-

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

1 Like

You most probably think about one of these methods:

https://rubyapi.org/3.0/o/kernel#method-i-caller

https://rubyapi.org/3.0/o/kernel#method-i-caller_locations

The first one returns Strings, the second one a Thread::Backtrace::Location which respond to methods like #lineno and #label which can help you achieve what I think you try to achieve.

ยทยทยท

On 8/29/21 1:23 AM, Die Optimisten wrote:

Hello,

How do I get the name of the method I'm in (perhaps with line-number) ?
(like the error-stack when failing)

thank you

Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;