methods

Hi
How do I get name of a proc when it is called?
Is there another way defined elsewhere (not in the proc/method itself)
to get all calls
(which method/proc-name is called when calling any method?)
How to ge the classname of the method called?

thank you Opti

you can apply a .class method to an instance method to get the class name. for instance

> [1,2,3].sort.class
=> Array

Thanks

Die Optimisten wrote:

···

How to ge the classname of the method called?

Procs don't have names.

objs.map { |o| ...what name do I have?...}

->() { or here? }.call

···

On Apr 13, 2022, at 01:48, Die Optimisten <inform@die-optimisten.net> wrote:

How do I get name of a proc when it is called?

Hi
Calling a proc (later) needs to bind it to a name, so I meant to get the
variable-name (or object id) of it.
The bigger question is how to interfere method-calls - any ideas?
thank you
Opti

···

Am 13.04.22 um 17:58 schrieb Ryan Davis:

On Apr 13, 2022, at 01:48, Die Optimisten <inform@die-optimisten.net> wrote:

How do I get name of a proc when it is called?

Procs don't have names.

objs.map { |o| ...what name do I have?...}

->() { or here? }.call

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

You could always assign the proc to a variable -- that will give it a "handle" you can grab.

Walter

···

On Apr 14, 2022, at 9:33 AM, Die Optimisten <inform@die-optimisten.net> wrote:

Hi
Calling a proc (later) needs to bind it to a name, so I meant to get the
variable-name (or object id) of it.
The bigger question is how to interfere method-calls - any ideas?
thank you
Opti

Am 13.04.22 um 17:58 schrieb Ryan Davis:

On Apr 13, 2022, at 01:48, Die Optimisten <inform@die-optimisten.net> wrote:

How do I get name of a proc when it is called?

Procs don't have names.

objs.map { |o| ...what name do I have?...}

->() { or here? }.call

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

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

How to (efficiently!) grab the variable name (from the object-id) - not
scanning all vars?

Opti

···

Am 14.04.22 um 15:35 schrieb Walter Lee Davis:

You could always assign the proc to a variable -- that will give it a "handle" you can grab.

Walter

You can't. Constants are special when applied to `Class` or `Module`
objects, but variables are
not storage locations. They are *labels*. If we theoretically had a
"owning_variable" method on
Object, what should be returned in the case of:

a = b = Object.new
a.owning_variable # => ??

The specialness of constants:

[1] pry(main)> foo = Class.new
=> #<Class:0x0000000159221460>
[2] pry(main)> foo.name
=> nil
[3] pry(main)> Foo = foo
=> Foo
[4] pry(main)> foo.name
=> "Foo"
[5] pry(main)>

-a

···

On Thu, Apr 14, 2022 at 9:41 AM Die Optimisten <inform@die-optimisten.net> wrote:

Am 14.04.22 um 15:35 schrieb Walter Lee Davis:
> You could always assign the proc to a variable -- that will give it a
"handle" you can grab.
>
> Walter

How to (efficiently!) grab the variable name (from the object-id) - not
scanning all vars?

--
Austin Ziegler • halostatue@gmail.com • austin@halostatue.ca
http://www.halostatue.ca/http://twitter.com/halostatue

You can pass a variable to proc itself.

14.04.2022 16:40, Die Optimisten пишет:

···

Am 14.04.22 um 15:35 schrieb Walter Lee Davis:

You could always assign the proc to a variable -- that will give it a "handle" you can grab.

Walter

How to (efficiently!) grab the variable name (from the object-id) - not
scanning all vars?

Opti

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