Sha256: 1071ea95c370a2d1dbc9e70a348dc7ff654bc224fdb2759d26f5da30e13ba64f

Contents?: true

Size: 874 Bytes

Versions: 13

Compression:

Stored size: 874 Bytes

Contents

class Module

  # Returns the root name of the module/class.
  #
  #   module Example
  #     class Demo
  #     end
  #   end
  #
  #   Demo.name       #=> Example::Demo
  #   Demo.basename   #=> Demo
  #
  # For anonymous modules this will provide a basename
  # based on Module#inspect.
  #
  #   m = Module.new
  #   m.inspect       #=> "#<Module:0xb7bb0434>"
  #   m.basename      #=> "Module_0xb7bb0434"
  #
  def basename
    if name and not name.empty?
      name.gsub(/^.*::/, '')
    else
      nil #inspect.gsub('#<','').gsub('>','').sub(':', '_')
    end
  end

end



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

  require 'test/unit'

  class TCModule < Test::Unit::TestCase

    def test_basename
      assert_equal( "TestCase", ::Test::Unit::TestCase.basename )
    end

  end

=end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
facets-1.4.3 lib/facets/core/module/basename.rb
facets-1.4.4 lib/facets/core/module/basename.rb
facets-1.4.5 lib/facets/core/module/basename.rb
facets-1.7.0 lib/facets/core/module/basename.rb
facets-1.7.30 lib/facets/core/module/basename.rb
facets-1.7.38 lib/facets/core/module/basename.rb
facets-1.7.46 lib/facets/core/module/basename.rb
facets-1.8.0 lib/facets/core/module/basename.rb
facets-1.8.20 lib/facets/core/module/basename.rb
facets-1.8.49 lib/facets/core/module/basename.rb
facets-1.8.51 lib/facets/core/module/basename.rb
facets-1.8.54 lib/facets/core/module/basename.rb
facets-1.8.8 lib/facets/core/module/basename.rb