Sha256: 4d98ce9d23b24cec6e4e50495a80395eaef031ef795f4383adf02e6d6c3936c4

Contents?: true

Size: 816 Bytes

Versions: 10

Compression:

Stored size: 816 Bytes

Contents

module Kernel

  private

  # Retreive the current running method name.
  #
  # There is a lot of debate on what to call this.
  # #me returns a symbol, not a string.
  #
  #   def tester; __method__; end
  #   tester  #=> :tester

  def callee
    /\`([^\']+)\'/.match(caller(1).first)[1].to_sym
  end

  # Technically __callee__ should provided alias names,
  # where __method__ should not. But we'll have to
  # leave that distinction to Ruby 1.9+.

  alias_method :__callee__, :callee
  alias_method :__method__, :callee

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_method_name
      assert_equal( "test_method_name", callee.to_s )
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-1.7.0 lib/facets/core/kernel/callee.rb
facets-1.7.30 lib/facets/core/kernel/callee.rb
facets-1.7.38 lib/facets/core/kernel/callee.rb
facets-1.7.46 lib/facets/core/kernel/callee.rb
facets-1.8.0 lib/facets/core/kernel/callee.rb
facets-1.8.20 lib/facets/core/kernel/callee.rb
facets-1.8.49 lib/facets/core/kernel/callee.rb
facets-1.8.51 lib/facets/core/kernel/callee.rb
facets-1.8.54 lib/facets/core/kernel/callee.rb
facets-1.8.8 lib/facets/core/kernel/callee.rb