Issue #5628 has been updated by trans (Thomas Sawyer).


Common case (for me) is when user selects a "plug-in" via a command line option. For example a pseudo test framework:

    $ mytest --reporter progress

Then in code:

    module MyTestFramework
      def self.reporters
        @reporters ||= {}
      end

      module Reporters
        class Base
          def self.inherited(subclass)
            MyTestFramework.reporters[subclass.basename.downcase] = subclass
          end
        end

        class Progress < Base
          ...
        end
      end
    end

Then reporters are very easy to lookup with command line option.

    MyTestFramework.reporters[reporter]   # i.e. reporter = 'progress'

That's just one example, but I have found the basic pattern to be useful in many such "pluggable" designs.

----------------------------------------
Feature #5628: Module#basename
https://bugs.ruby-lang.org/issues/5628#change-25510

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 2.0.0


Something I use fairly often:

    some_module.name.split("::").last

It's useful for things like factory methods. It would be much nicer if we had:

    class Module
      def basename
        name.split("::").last
      end
    end




-- 
http://bugs.ruby-lang.org/