Sha256: c7485436a333451e8f5aa44dbd43487583889972216a58dca963aeda3cf388b4

Contents?: true

Size: 602 Bytes

Versions: 10

Compression:

Stored size: 602 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"
  #
  # CREDIT: Trans

  def basename
    if name and not name.empty?
      name.gsub(/^.*::/, '')
    else
      nil #inspect.gsub('#<','').gsub('>','').sub(':', '_')
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/module/basename.rb
facets-2.8.3 lib/core/facets/module/basename.rb
facets-2.8.2 lib/core/facets/module/basename.rb
facets-2.8.1 lib/core/facets/module/basename.rb
facets-2.8.0 lib/core/facets/module/basename.rb
facets-2.7.0 lib/core/facets/module/basename.rb
facets-2.6.0 lib/core/facets/module/basename.rb
facets-2.5.1 lib/core/facets/module/basename.rb
facets-2.5.0 lib/core/facets/module/basename.rb
facets-2.5.2 lib/core/facets/module/basename.rb