Sha256: d8035e25572f7b3deaf3ca911324baf48ebe7e4ba63d24e153129f2d4a9de0a9

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

module Mutant
  class Subject
    # Abstract base class for method subjects
    class Method < self

      # Test if method is public
      #
      # @return [true]
      #   if method is public
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      abstract_method :public?

      # Return method name
      #
      # @return [Symbol]
      #
      # @api private
      #
      def name
        node.children[self.class::NAME_INDEX]
      end

    private

      # Return scope
      #
      # @return [Class, Module]
      #
      # @api private
      #
      def scope
        context.scope
      end

      # Return subtype identifier
      #
      # @return [String]
      #
      # @api private
      #
      def subtype
        "#{context.identification}#{self.class::SYMBOL}#{name}"
      end

      # Instance method subjects
      class Instance < self

        NAME_INDEX = 0
        SYMBOL = '#'.freeze

        # Test if method is public
        #
        # @return [true]
        #   if method is public
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def public?
          scope.public_method_defined?(name)
        end
        memoize :public?

      private

      end # Instance

      # Singleton method subjects
      class Singleton < self

        NAME_INDEX = 1
        SYMBOL = '.'.freeze

        # Test if method is public
        #
        # @return [true]
        #   if method is public
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def public?
          scope.singleton_class.public_method_defined?(name)
        end
        memoize :public?

      end # Singleton

    end # Method
  end # Subject
end # Mutant

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mutant-0.3.0.beta8 lib/mutant/subject/method.rb
mutant-0.3.0.beta7 lib/mutant/subject/method.rb
mutant-0.3.0.beta6 lib/mutant/subject/method.rb
mutant-0.3.0.beta5 lib/mutant/subject/method.rb
mutant-0.3.0.beta4 lib/mutant/subject/method.rb
mutant-0.3.0.beta3 lib/mutant/subject/method.rb
mutant-0.3.0.beta2 lib/mutant/subject/method.rb