Module: HatiCommand::Callee::CalleeClassMethods

Defined in:
lib/hati_command/callee.rb

Overview

Class methods that are extended to classes including Callee. Provides the callable interface at the class level.

Instance Method Summary collapse

Instance Method Details

#__caller_methodSymbol

This method checks if a caller method has been set; if not, it defaults to ‘:call`.

Returns:

  • (Symbol)

    The name of the method to call.



52
53
54
# File 'lib/hati_command/callee.rb', line 52

def __caller_method
  @__caller_method || :call
end

#call {|Object| ... } ⇒ Object

Creates a new instance and calls its ‘call` method with the given arguments. This method implements the callable pattern, allowing the class to be used like a function while maintaining object-oriented principles.

Examples:

Without block

MyCallable.call(arg1, arg2)

With configuration block

MyCallable.call(input) do |instance|
  instance.configure(option: value)
end

Parameters:

  • args (Array)

    Arguments to be passed to the instance’s call method

Yields:

  • (Object)

    Optional block that yields the new instance before calling

Yield Parameters:

  • instance (Object)

    The newly created instance

Returns:

  • (Object)

    The result of the instance method call



71
72
73
74
75
76
77
# File 'lib/hati_command/callee.rb', line 71

def call(...)
  obj = new

  yield(obj) if block_given?

  obj.send(__caller_method, ...)
end

#call_as(method_name) ⇒ void

This method returns an undefined value.

This method allows you to configure command call method name such as: :execute, :perform, etc. Note: method call_as and command main instance method should much

Parameters:

  • method_name (Symbol)

    The name of the alias to create for the ‘call` method.



98
99
100
101
102
# File 'lib/hati_command/callee.rb', line 98

def call_as(method_name)
  @__caller_method = method_name

  singleton_class.send(:alias_method, method_name, :call)
end