Sha256: aee0563b015b3da96e6aed3f5a960785bc8c5cb2bfa6e43d42d12b4a6aeb8e3e

Contents?: true

Size: 506 Bytes

Versions: 7

Compression:

Stored size: 506 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 NameExample
    #     def foo; end
    #   end
    #
    #   meth = NameExample.instance_method(:foo)
    #
    #   meth.name.to_sym  #=> :foo
    #
    # CREDIT: Trans

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

  end

end

Version data entries

7 entries across 6 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/unboundmethod/name.rb
facets-2.9.2 lib/core/facets/unboundmethod/name.rb
facets-2.9.2 src/core/facets/unboundmethod/name.rb
facets-2.9.1 lib/core/facets/unboundmethod/name.rb
facets-2.9.0 lib/core/facets/unboundmethod/name.rb
facets-2.9.0.pre.2 lib/core/facets/unboundmethod/name.rb
facets-2.9.0.pre.1 lib/core/facets/unboundmethod/name.rb