Is there a method I can call where:

If I have:

class Blek
    def bM
  puts "trace #{self.somemethod}"
    end
end

bo = Blek.new
bo.bM

It will give me:

trace bo.bM
or
trace bM

???

I want to set up stuff that tells me what method I am in, largely for raising exceptions in various circumstances, but I want to control the message myself, so I'd like specifically knowledge of the method name available as stated.

···

--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

Xeno Campanoli / Eskimo North and Gmail wrote:

so I'd like specifically knowledge of the method name available as
stated.

The __method__ method should do the trick:

ruby -v: ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
irb(main):001:0> def foo
irb(main):002:1> p __method__
irb(main):003:1> end
=> nil
irb(main):004:0> foo
:foo
=> :foo
irb(main):005:0>

That one is implemented since 1.8.7 I think. The class name is available
via #class.

Marvin

···

--
Posted via http://www.ruby-forum.com/\.

__method__ or __callee__

···

On Jun 18, 4:03 pm, Xeno Campanoli / Eskimo North and Gmail <xeno.campan...@gmail.com> wrote:

If I have:

class Blek
def bM
puts "trace #{self.somemethod}"
end
end

bo = Blek.new
bo.bM

It will give me:

trace bo.bM
or
trace bM

???

I want to set up stuff that tells me what method I am in, largely for raising
exceptions in various circumstances, but I want to control the message myself,
so I'd like specifically knowledge of the method name available as stated.
--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

__method__ or __callee__

Thank you. __method__ seems to work, but __callee__ seems to fail, and I cannot find it in pickaxe:

./test.rb:8:in `bm': undefined local variable or method `__callee__' for #<Blek:0xb78989f8> (NameError)
  from ./test.rb:18

I tried several variations of that too, and they all fail. Still, you got me going. Thank you very much.

Sincerely, Xeno.
xc

···

On 10-06-18 01:32 PM, Intransition wrote:

On Jun 18, 4:03 pm, Xeno Campanoli / Eskimo North and Gmail > <xeno.campan...@gmail.com> wrote:

If I have:

class Blek
     def bM
         puts "trace #{self.somemethod}"
     end
end

bo = Blek.new
bo.bM

It will give me:

trace bo.bM
or
trace bM

???

I want to set up stuff that tells me what method I am in, largely for raising
exceptions in various circumstances, but I want to control the message myself,
so I'd like specifically knowledge of the method name available as stated.
--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

It's a 1.9. thing:

  http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l168

···

On Jun 18, 4:44 pm, Xeno Campanoli / Eskimo North and Gmail <xeno.campan...@gmail.com> wrote:

On 10-06-18 01:32 PM, Intransition wrote:

> __method__ or __callee__

Thank you. __method__ seems to work, but __callee__ seems to fail, and I cannot
find it in pickaxe:

> ./test.rb:8:in `bm': undefined local variable or method `__callee__' for #<Blek:0xb78989f8> (NameError)
> from ./test.rb:18