Sha256: 6e532c7878dd61e666e9bba70504ec605dd4f25e12618990f26a745f5bce3f71

Contents?: true

Size: 820 Bytes

Versions: 22

Compression:

Stored size: 820 Bytes

Contents

require 'facets/core/binding/caller'

class Binding

  # 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; p methodname; end
  #   tester  #=> "tester"
  #
  def methodname
    name = /\`([^\']+)\'/.match(caller(1).first)[1]
    return name
  end

end



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

  require 'test/unit'

  class TCBinding < Test::Unit::TestCase

    def setup
      a = 1
      b = 2
      x = "hello"
      # the line number must be updated if it moves
      @bind = binding; @this_line_no = 25
    end

    def test_methodname
      assert_equal( 'setup', @bind.methodname )
    end

  end

=end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
facets-1.3.0 lib/facets/core/binding/method_name.rb
facets-1.2.0 lib/facets/core/binding/method_name.rb
facets-1.2.1 lib/facets/core/binding/method_name.rb
facets-1.3.2 lib/facets/core/binding/method_name.rb
facets-1.3.3 lib/facets/core/binding/method_name.rb
facets-1.3.1 lib/facets/core/binding/method_name.rb
facets-1.4.2 lib/facets/core/binding/method_name.rb
facets-1.4.0 lib/facets/core/binding/method_name.rb
facets-1.4.1 lib/facets/core/binding/method_name.rb
facets-1.4.3 lib/facets/core/binding/method_name.rb
facets-1.4.4 lib/facets/core/binding/method_name.rb
facets-1.4.5 lib/facets/core/binding/method_name.rb
facets-1.7.30 lib/facets/core/binding/method_name.rb
facets-1.7.38 lib/facets/core/binding/method_name.rb
facets-1.7.0 lib/facets/core/binding/method_name.rb
facets-1.7.46 lib/facets/core/binding/method_name.rb
facets-1.8.49 lib/facets/core/binding/method_name.rb
facets-1.8.0 lib/facets/core/binding/method_name.rb
facets-1.8.20 lib/facets/core/binding/method_name.rb
facets-1.8.51 lib/facets/core/binding/method_name.rb