Sha256: 4fe9cfc627a12235977b160bdaa35b533db81e9b232bc4fe916c2645918247d7

Contents?: true

Size: 479 Bytes

Versions: 3

Compression:

Stored size: 479 Bytes

Contents

class UnboundMethod

  unless method_defined?(:name) # 1.8.7+

    # Return the name of the method.
    #
    # Be aware that in ruby 1.9 UnboundMethod#name is defined already,
    # but it returns a Symbol not a String.
    #
    #   class X
    #     def foo; end
    #   end
    #
    #   meth = X.instance_method(:foo)
    #
    #   meth.name  #=> :foo
    #
    # CREDIT: Trans

    def name
      i = to_s.rindex('#')
      to_s.slice(i+1...-1).to_sym
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/unboundmethod/name.rb
facets-2.8.3 lib/core/facets/unboundmethod/name.rb
facets-2.8.2 lib/core/facets/unboundmethod/name.rb