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
-
#__caller_method ⇒ Symbol
This method checks if a caller method has been set; if not, it defaults to ‘:call`.
-
#call {|Object| ... } ⇒ Object
Creates a new instance and calls its ‘call` method with the given arguments.
-
#call_as(method_name) ⇒ void
This method allows you to configure command call method name such as: :execute, :perform, etc.
Instance Method Details
#__caller_method ⇒ Symbol
This method checks if a caller method has been set; if not, it defaults 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.
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
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 |