Sha256: 4f6a1c468589ed002b2f43f9de9cef9b4b6e1e540242500c297aee0c5a62179b

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Command
    module Utils

      module_function

      def try(object, method_name, *args, include_private: false)
        return unless object.respond_to?(method_name, include_private)

        object.send(method_name, *args)
      end

      def hook(object, method_name, *args)
        try(object, method_name, *args, include_private: true)
      end

      def call(object, method_name_or_proc)
        if method_name_or_proc.is_a?(Symbol) || method_name_or_proc.is_a?(String)
          object.send(method_name_or_proc)
        elsif method_name_or_proc.is_a?(Proc)
          object.instance_eval(&method_name_or_proc)
        else
          method_name_or_proc
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lite-command-2.1.0 lib/lite/command/utils.rb