Sha256: b979c941c4efe244a1fb0787be9ca64f5444fc7c51451c891237eb33425cfc86

Contents?: true

Size: 1.63 KB

Versions: 8

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Utils
    module Module
      class ClassMethodDefined < Support::Command
        ##
        # @!attribute [r] mod
        #   @return [Class, Module]
        #
        attr_reader :mod

        ##
        # @!attribute [r] method_name
        #   @return [String, Symbol]
        #
        attr_reader :method_name

        ##
        # @!attribute [r] public
        #   @return [Boolean]
        #
        attr_reader :public

        ##
        # @!attribute [r] protected
        #   @return [Boolean]
        #
        attr_reader :protected

        ##
        # @!attribute [r] private
        #   @return [Boolean]
        #
        attr_reader :private

        ##
        # @param mod [Class, Module]
        # @param method_name [String, Symbol]
        # @param public [Boolean]
        # @param protected [Boolean]
        # @param private [Boolean]
        # @return [void]
        #
        # @internal
        #   NOTE: `protected` is set to `true` by default to keep the same semantics as `Module#method_defined?`.
        #   - https://ruby-doc.org/core-3.1.0/Module.html#method-i-method_defined-3F
        #
        def initialize(mod, method_name, public: true, protected: true, private: false)
          @mod = mod
          @method_name = method_name
          @public = public
          @protected = protected
          @private = private
        end

        ##
        # @return [Boolean]
        #
        def call
          Utils::Method.defined?(method_name, mod.singleton_class, public: public, protected: protected, private: private)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.19.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.18.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.17.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.16.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.15.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.14.0 lib/convenient_service/utils/module/class_method_defined.rb
convenient_service-0.13.0 lib/convenient_service/utils/module/class_method_defined.rb