Sha256: 1d3df9cf011405a796533c486c4f4b672613391353e38657efac2bb838a902dc

Contents?: true

Size: 970 Bytes

Versions: 12

Compression:

Stored size: 970 Bytes

Contents

module Kernel

  private

  # Retreive the current running method.
  # There is a lot of debate on what to call this.
  # #method_name differs from #called only by the fact
  # that it returns a string, rather then a symbol.
  #
  #   def tester; method_name; end
  #   tester  #=> "tester"
  #
  def methodname
    name = /\`([^\']+)\'/.match(caller(1).first)[1]
    return name
  end

  # depricate?
  alias_method :method_name, :methodname

end



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

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_method_name
      # For some reason this was returning a string
      # even when aliased to #called. Why?
      # Well, I couldn't seem to fix it, so I just
      # accepted it as fact and made +method_name+ 
      # purposefully work that way.
      assert_equal( "test_method_name", method_name )
    end

  end

=end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/kernel/method_name.rb
facets-1.0.0 lib/facet/kernel/method_name.rb
facets-1.0.3 packages/core/lib/facet/kernel/method_name.rb
facets-1.1.0 lib/facet/kernel/method_name.rb
facets-1.2.0 lib/facets/core/kernel/method_name.rb
facets-1.2.1 lib/facets/core/kernel/method_name.rb
facets-1.3.0 lib/facets/core/kernel/methodname.rb
facets-1.3.1 lib/facets/core/kernel/methodname.rb
facets-1.3.2 lib/facets/core/kernel/methodname.rb
facets-1.3.3 lib/facets/core/kernel/methodname.rb
facets-1.4.0 lib/facets/core/kernel/methodname.rb
facets-1.4.1 lib/facets/core/kernel/methodname.rb